Abdurraziq / ZMPT101B-arduino

Arduino library for ZMPT101B voltage sensor.
MIT License
67 stars 32 forks source link

How to measure three phase voltage #11

Closed Dezolator99 closed 2 years ago

Dezolator99 commented 2 years ago

how to use this library to measure 3x ZMPT103 connected to A0, A1, A2. I want to measure L1 to N, L2 to N, L3 to N, ie 3x 240V

Abdurraziq commented 2 years ago

Hi @Dezolator99

First create 3 objects of class ZMPT101Bfor each ZMPTsensor you are using. example;

ZMPT101B vl1(A0);
ZMPT101B vl2(A1);
ZMPT101B vl3(A2);

Then, if you want to calibrate the ZMPT101B please do so in setup(). But make sure that when you run it there is no voltage at the ZMPT . AC terminal example;

void setup()
{
  Serial.begin(9600);
  Serial.println("Calibrating... Ensure that no current flows through the sensor at this moment");
  delay(100);
  vl1.calibrate();
  vl2.calibrate();
  vl3.calibrate();
  Serial.println("Done!");
}

Then you can read the sensor readings as follows;

void loop()
{
  float volt_l1 = vl1.getVoltageAC();
  float volt_l2 = vl2.getVoltageAC();
  float volt_l3 = vl3.getVoltageAC();
  Serial.println(String("L1 = ") + volt_l1 + " V");
  Serial.println(String("L3 = ") + volt_l2 + " V");
  Serial.println(String("L3 = ") + volt_l3 + " V");
  delay(1000);
}

Please note that the getVoltageAC() method uses the default frequency value of 50 Hz. If you are in the 60Hz standard region please enter argument 60 into the getVoltageAC(60) input method parameter. Example;

float volt_l1 = vl1.getVoltageAC(60);

The last thing to remember is that this sensor is an analog sensor, for which you sometimes need to calibrate and set the sensitivity via setSensitivity() into the program.

Dezolator99 commented 2 years ago

Well thank you, your code works. I had a similar idea. At the beginning I defined the inputs: ZMPT101B voltageSensor (A0); ZMPT101B voltageSensor (A1); ZMPT101B voltageSensor (A2); I was still trying to assign a variable like this: L1 = ZMPT101B voltageSensor(A0); L2 = ZMPT101B voltageSensor(A1); L3. = ZMPT101B voltageSensor(A2); but even that was wrong.

Abdurraziq commented 2 years ago

Great... 😁

FYI, ZMPT101B is a class in c++. so we need to treat it differently from a regular function, For example when we want to create an object then we have to define it like this;

NameOfClass nameOfObject(ConstructorParameters);

for example;

ZMPT101B   voltageOfL1 (A0);
   ↑           ↑         ↑
class      object      ConstructorParameters

and remember not to create an object with the same name, for example when you already use the object name voltageOfL1 then don't use that name again to create another new object.