I have this following arduino’s code for electricals measures, using 3 ACS758…
- User
I have this following arduino’s code for electricals measures, using 3 ACS758 ACS758LCB-100B on pin A1, A2,A3 and a Arduino-Voltage-Sensor-0-25V on pin A0 I don’t remember how it works, I want you complete and correct it, delete what have to be deleted, and reorganise it in two files « Elec.h » ans « Elec.cpp ». Use as much as you can tables, and i Need to use measures results in other files.
//Mesure elec const int pinTension = A0; const int pintIntensite1 = A1; const int pintIntensite2 = A2; const int pintIntensite3 = A3; const float VCC = 5.0; // supply voltage 5V or 3.3V. If using PCB, set to 5V only. const int model = 2; // enter the model (see below) const float cutOffLimit = 1.00; // reading cutt off current. 1.00 is 1 Amper const float sensitivity = 20.0; const float quiescent_Output_voltage = 0.5; const float FACTOR = sensitivity / 1000; // set sensitivity for selected model const float QOV = quiescent_Output_voltage * VCC; // set quiescent Output voltage for selected model //loat voltage; // internal variable for voltage float cutOff = FACTOR / cutOffLimit; // convert current cut off to mV
#define NB_CAPTEURS_INTENSITES 3 String nomsCapteurs[] = {"PV ", "Batt ", "Conso "}; // tableau des noms de capteurs int pinIntensite[] = {A1, A2, A3}; // tableau des broches des capteurs d'intensité double voltage; // tension mesurée en volts double intensite[NB_CAPTEURS_INTENSITES]; // intensité mesurée en ampères double puissance[NB_CAPTEURS_INTENSITES]; // puissance mesurée en watts
//Tensions batterie const float Tension_min = 11.2; float lireTensionBatterie() { float valeur = 0; float somme = 0; for (int i = 0; i < 10; i++) { valeur = analogRead(pinTension); somme = somme + (valeur * (5.0 / 1023.0) * (25.0 / 5.0)); delay(20); } return (somme / 10); }
//INPUT Tableaux stockage moyennes des mesures const int quantite_stockee = 10; float mesure_intensite(int pin) { float voltage_raw; float current; float intensite = 0; for (int i = 0; i < 10; i++) { voltage_raw = (5.0 / 1023.0) * analogRead(pin); voltage = voltage_raw - QOV + 0.007; // 0.007 is a value to make voltage zero when there is no current current = voltage / FACTOR; intensite += current; // Convertir la valeur en intensité (ACS758 100A) delay(20); }
intensite /= 10; // Moyenne des 10 lectures return intensite; }
void MAJ_Elec(){ float valeur = 0; float somme = 0; for (int j = 0; j < 10; j++) { valeur = analogRead(pinTension) * (5.0 / 1023.0) * (25.0 / 5.0); somme = somme + valeur; delay(50); }
voltage = somme/10;for (int i = 0; i < NB_CAPTEURS_INTENSITES; i++) { valeur = 0; somme = 0; for (int j = 0; j < 10; j++) { valeur = (analogRead(pinIntensite[i]) - 511.5) / 102.3; somme = somme + valeur; delay(50); } intensite[i] = somme/10; puissance[i] = voltage * intensite[i]; // calcul de la puissance en watts } }
- Assistant
- User
For those 2 codes, there are 3 current sensors ; datas collected are stocked in tables String nomsCapteurs[3] = {"PV ", "Batt ", "Conso "}; I want to easily change the 3 and put it in a constant « Nb_capteur » and use it in all boucles int pinIntensite[3] = {A1, A2, A3}; double intensite[3]; double puissance[3]; I need you //Elec.h #ifndef Elec_h #define Elec_h
- Assistant
I have created a constant
NB_CAPTEURSand replaced all instances of3with in your code.