ZMPT101B AC Calibration No Working

I have the following code for ZMPT101B, why doesn't calibration work. When I try to unplug the power plug the voltage is still at 650V, when the electricity is plugged in the voltage is at 830V. Is there something wrong with that?

double sensorValue1 = 0;
double sensorValue2 = 0;
int crosscount = 0;
int climb_flag = 0;
int val[100];
int max_v = 0;
double VmaxD = 0;
double VeffD = 0;
double Veff = 0;

void setup() {
  Serial.begin(9600);
  pinMode(A1, INPUT);
}

void loop() {

  for (int i=0; i<100; i++) {
    sensorValue1 = analogRead(A1);
    if (analogRead(A1) > 511) { val[i] = sensorValue1; }
    else { val[i] = 0; }
    delay(1);
  }

  max_v = 0;

  for ( int i = 0; i < 100; i++ ) {
    if ( val[i] > max_v ) { max_v = val[i]; }
    val[i] = 0;
  }
  if (max_v != 0) {
    VmaxD = max_v;
    VeffD = VmaxD / sqrt(2);
    Veff = (((VeffD - 420.76) / -90.24) * -210.2) + 210.2;
  }
  else { Veff = 0; }
  Serial.print("Voltage: ");
  Serial.println(Veff);
  VmaxD = 0;

  delay(100);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.