Electgpl

ARDUINO - Medidor Potencia

Apr 19th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.77 KB | None | 0 0
  1. // -- variables and pins definition ------------------
  2. const int analogInPin = A0;         // analog input pin
  3. int retardo = 2;                    // (tiempo (s.) entre visionados)
  4. float lectura, ff, pKW, iA, vV, vS, S_Ratio;
  5. // -- initialize serial comm & parameters ------------
  6. void setup() {
  7.    Serial.begin(9600);
  8.    S_Ratio = 36.5;                  // Sensor/ratio (mV/mA ) : 36.5
  9.    vV = 230;                        // valor de tension a computar
  10.    ff = 5;                          // freq. factor / (50Hz -> 5 / 60Hz -> 4.15)
  11. }
  12. // -- smooth read routine ----------------------------
  13. float smoothread(float fc){         // fc (factor corrector)
  14.    int ni = 35;                     // n. de iteraciones => smooth
  15.                                     // (ni) => rango 10 a 50 mejor promedio [smoothing]
  16.    float retorno = 0.0;
  17.    for(int x = 0; x< ni; x++){
  18.       do{                           // espero paso por cero
  19.          delayMicroseconds(100);
  20.       }while(analogRead(0) != 0);
  21.       delay (ff); // espera centro de ciclo
  22.       delay (10); // estabilizacion CAD
  23.       retorno = retorno +(analogRead(0)*fc);
  24.    }
  25.    return retorno / ni;
  26. }
  27. // -- main loop --------------------------------------
  28. void loop(){
  29.    lectura = smoothread (1) / 1.41; // lectura (rms)
  30.    vS = (lectura * 0.0048);         // valor de C.A.D.
  31.    iA = (lectura * S_Ratio)/1000;   // Intensidad (A)
  32.    pKW = (vV * iA)/1000;            // Potencia (kW)
  33.    Serial.print("\n- Tension predefinida [V] --> " );
  34.    Serial.print(vV,0);
  35.    Serial.print("\n- Lectura del sensor [V] --> " );
  36.    Serial.print(vS,3);
  37.    Serial.print("\n- Intensidad calculada [A] --> " );
  38.    Serial.print(iA,3);
  39.    Serial.print("\n- Potencia calculada [kW] --> " );
  40.    Serial.print(pKW,3);
  41.    delay(retardo * 1000);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment