Multiple voltage sensor ZMPT101B

i’m modifying a code from a youtube video i’ve seen recently but i’m not sure on what to do to the code to add another another two voltage sensor.Smart Energy Monitor is the project but i want to add the two voltage sensor for a lighting circuit breaker and socket circuit breaker so there will be main voltage,lighting voltage and socket voltage.Another feature i want to add is notify at blynk when there is no presence of electricity on one of the voltage sensors.Here is the code:

//#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
//LiquidCrystal lcd(13, 12, 14, 27, 26, 25);
#define BLYNK_PRINT Serial
#include "EmonLib.h"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
EnergyMonitor emon;
#define vCalibration 83.3
#define currCalibration 0.50
BlynkTimer timer;
char auth[] = "8pLvHwMeurO0_Zojr9hXoxBYw6IGgT7C"; //Your auth token from email
char ssid[] = "Electro Gadget";    //Type your WiFi name
char pass[] = "**********";    //Type your WiFi password
float kWh = 0;
unsigned long lastmillis = millis();
void myTimerEvent()
{
  emon.calcVI(20, 2000);
  kWh = kWh + emon.apparentPower * (millis() - lastmillis) / 3600000000.0;
  yield();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Vrms:");
  lcd.print(emon.Vrms, 2);
  lcd.print("V");
  lcd.setCursor(0, 1);
  lcd.print("Irms:");
  lcd.print(emon.Irms, 4);
  lcd.print("A");
  delay(2500);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Power:");
  lcd.print(emon.apparentPower, 4);
  lcd.print("W");
  lcd.setCursor(0, 1);
  lcd.print("kWh:");
  lcd.print(kWh, 4);
  lcd.print("W");
  delay(2500);
  lastmillis = millis();
  Blynk.virtualWrite(V0, emon.Vrms);
  Blynk.virtualWrite(V1, emon.Irms);
  Blynk.virtualWrite(V2, emon.apparentPower);
  Blynk.virtualWrite(V3, kWh);
}
void setup()
{
  //lcd.begin(16, 2);
  lcd.init();                      
  lcd.backlight();
  Blynk.begin(auth, ssid, pass);
  emon.voltage(35, vCalibration, 1.7); // Voltage: input pin, calibration, phase_shift
  emon.current(34, currCalibration);   // Current: input pin, calibration.
  timer.setInterval(5000L, myTimerEvent);
  lcd.setCursor(3, 0);
  lcd.print("Smart Energy");
  lcd.setCursor(5, 1);
  lcd.print("Monitor");
  delay(3000);
  lcd.clear();
}
void loop()
{
  Blynk.run();
  timer.run();
}

Welcome, Omar, to the OEM forum.

You will need to set up at least 3 instances of EnergyMonitor like this

but each of course has a different name (main, lighting, socket?).
Then you need to use
main.voltage(unsigned int _inPinV, double _VCAL, double _PHASECAL); to define the pin for this voltage, so you need to repeat these lines for each supply:

  emon.voltage(35, vCalibration, 1.7); // Voltage: input pin, calibration, phase_shift
  emon.current(34, currCalibration);   // Current: input pin, calibration.

and likewise to extract the values Vrms, realPower, etc.
Blynk.virtualWrite(V0, emon.Vrms); etc

I don’t know anything about blynk so I can’t help you with this aspect. You will need to add a test in your sketch
bool lowVoltage = lighting.Vrms < 50 ? true : false;
and somehow use lowVoltage in Blynk.

Hi Robert,
I try to create a powermeter (EMONCMS) based on the same code, without blynk. I’m using a zmpt101b, sct-013 and an esp32 with 5v powerd. Input voltage is 230v.
I have problems to calibrate. How to define the calibrate
Values for v oltage and current measurement?
Thanks for Your help.
Uwe

For the emonTx & emonPi, the calibration constant is the voltage or current that would give 1 V at the ADC input. I don’t have an ESP32, so I cannot prove that it is the same, but I think it will be.

will it be like this?

#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Wire.h>
#define BLYNK_PRINT Serial
#include "EmonLib.h"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

EnergyMonitor emon;
EnergyMonitor emon1;
EnergyMonitor emon2;

#define vCalibration 83.3
#define vCalibration1 83.3
#define vCalibration2 83.3
#define currCalibration 0.50

BlynkTimer timer;

char auth[] = "apYc_VS8FMFL6SWw5TMM4HXZRWN4ee4p";
char ssid[] = "Omar";
char pass[] = "password";

float kWh = 0;
unsigned long lastmillis = millis();

void myTimerEvent()
{
  emon.calcVI(20, 2000);
  kWh = kWh + emon.apparentPower * (millis() - lastmillis) / 3600000000.0;
  yield();
  Serial.print("Vrms: ");
  Serial.print(emon.Vrms, 2);
  Serial.print("V");

  Serial.print("\tIrms: ");
  Serial.print(emon.Irms, 4);
  Serial.print("A");

  Serial.print("\tPower: ");
  Serial.print(emon.apparentPower, 4);
  Serial.print("W");

  Serial.print("\tkWh: ");
  Serial.print(kWh, 5);
  Serial.println("kWh");

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Main:");
  lcd.print(emon.Vrms, 2);
  lcd.print("V");
  lcd.setCursor(0, 1);
  lcd.print("Irms:");
  lcd.print(emon.Irms, 4);
  lcd.print("A");
  delay(1500);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Power:");
  lcd.print(emon.apparentPower, 4);
  lcd.print("W");
  lcd.setCursor(0, 1);
  lcd.print("kWh:");
  lcd.print(kWh, 4);
  lcd.print("W");
  delay(1500);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Lighting:");
  lcd.print(emon1.Vrms, 2);
  lcd.print("V");
  lcd.setCursor(0, 1);
  lcd.print("SSO:");
  lcd.print(emon2.Vrms, 2);
  lcd.print("V");
  delay(1500);

  lastmillis = millis();

  Blynk.virtualWrite(V0, emon.Vrms);
  Blynk.virtualWrite(V13, emon.Irms);
  Blynk.virtualWrite(V2, emon.apparentPower);
  Blynk.virtualWrite(V3, kWh);
  Blynk.virtualWrite(V4, emon1.Vrms);
  Blynk.virtualWrite(V5, emon2.Vrms);
}

void setup()
{
  Serial.begin(9600);
  lcd.begin();
  lcd.backlight();
  Blynk.begin(auth, ssid, pass, "blynk.cloud");
  emon.voltage(35, vCalibration, 1.7);
  emon.current(34, currCalibration);
  emon1.voltage(32, vCalibration1, 1.7);
  emon2.voltage(33, vCalibration2, 1.7);
  timer.setInterval(5000L, myTimerEvent);
  lcd.setCursor(0, 0);
  lcd.print("Smart Notification For");
  lcd.setCursor(0, 1);
  lcd.print("Power Interupptions");
  delay(3000);
  lcd.clear();
}

void loop()
{
  Blynk.run();
  timer.run();
}

This looks as if you’re going in the right direction, but as I wrote above, I know nothing about Blynk. Somewhere, the class method calcVI needs to be called for each instance of EnergyMonitor so that the readings can be refreshed.

so how do i get only the value for two of those sensors

I think you need to look at the information from Blynk.

In a normal Arduino sketch, inside loop( ) you would call (for example)

emon.calcVI(...);
emon1.calcVI(...);
emon2.calcVI(...);

every few seconds and this would read and make the 3 voltages emon.Vrms, emon1.Vrms & emon2.Vrms available as you have them in your code.

I do not know how Blynk works, so I cannot help you.