IOT

IoT Based Electricity Energy Meter using ESP32 & Blynk

Electricity is one of the most important blessings that science has given to mankind. It also had become a part of modern life and cannot think of a world without it. People use electricity for lighting, heating, cooling, and refrigeration and for operating appliances, computers, electronics, machinery, and public transportation systems. As the technology is developing day by day and dependencies on the electrical appliances increase, the usage and requirement for electricity also increase rapidly.

In this blog, we will learn how to create our own IoT-based electricity energy meter using the ESP32 and how to monitor data using the Blynk application. With the current technology, you need to go to the meter reading room and take down readings. As a result, keeping track of your electricity consumption is a time-consuming chore. We can use the Internet of Things to automate this. By automating distant data collecting, the Internet of Things saves time and money. In recent years, the Smart Energy Meter has attracted a lot of attention from all over the world. Come on, let’s start building an IoT-based electricity energy meter.

Proposed System:

We must choose a current and voltage sensor so that the current and voltage can be measured and the power consumption and total power utilized can be calculated. The SCT-013 is the best current sensor on the market. The SCT-013 Non-Invasive AC Current Sensor Split Core Type Clamp Meter Sensor measures AC current up to 100 amperes. Similarly, the AC Voltage Sensor Module ZMPT101B is the ideal voltage sensor. When we need to measure accurate AC voltage with a voltage transformer, the ZMPT101B AC Voltage Sensor is the ideal option.

Using the SCT-013 Current Sensor & ZMPT101B Voltage Sensor, we can measure the all required parameters needed for Electricity Energy Meter. We will interface the SCT-013 Current Sensor & ZMPT101B Voltage Sensor with ESP32 Wifi Module & Send the data to the Blynk Application. The Blynk Application Dashboard will display the Voltage, Current, Power & total unit consumed in kWh.

Components Required:

  • ESP32 Development Board (ESP-WROOM-32)
  • ZMPT101B AC Voltage Sensor Module
  • SCT-013-030 Non-invasive AC Current Sensor
  • 16X2 I2C LCD Display
  • Resistors-10K,100ohm
  • Capacitors-10uF
  • Connecting wire
  • Breadboard

SCT-013 Current Sensor

SCT-013 Current Sensor

The SCT-013 is a non-invasive AC current sensor with a split core type clamp meter sensor that can measure up to 100 amperes of AC current. CTs are current transformers that are used to measure alternating current. They’re very useful for calculating the total electricity consumption of a building. Without any high-voltage electrical work, the SCT-013 current sensors can be clipped straight to the live or neutral wire.

A current transformer has a primary winding, a magnetic core, and a secondary winding, much like any other transformer. The secondary winding is made up of numerous twists of tiny wires that are placed within the transformer’s case.

Specifications

  • Input Current: 0-30A AC
  • Output Signal: DC 0-1 V
  • Non-linearity: 2-3 %
  • Build-in sampling resistance (RL): 62 Ω
  • Turn Ratio: 1800:1
  • Resistance Grade: Grade B
  • Work Temperature: -25 °C~+70 °C
  • Dielectric Strength (between shell and output): 1000 V AC / 1 min 5 mA

ZMPT101B AC Single Phase Voltage Sensor

ZMPT101B

The ZMPT101B AC Single Phase voltage sensor module is based on a high-precision ZMPT101B voltage transformer that is used to measure accurate AC voltage. This is an excellent option for measuring AC voltage with an Arduino or an ESP32.

The Modules can measure voltage within a range of 250V AC and change the analog output accordingly. The module is easy to operate, and it has a multi-turn trim potentiometer for calibrating and modifying the ADC output.

Specifications

  • Voltage up to 250 volts can be measured
  • Lightweight with on-board micro-precision voltage transformer
  • High precision on-board op-amp circuit
  • Operating temperature : 40ºC ~ + 70ºC
  • Supply voltage 5 volts to 30 volts

Circuit Diagram & Hardware Setup

Let’s look at the circuit design for an IoT-based electricity energy meter that uses the ESP32. Fritzing software was used to design the circuit.

IoT Based Electricity Energy Meter

The connection diagram is straightforward. SCT-013 Current Sensor and ZMPT101B Voltage Sensor VCC are both linked to the Vin of the ESP32, which is a 5V supply. Both modules’ GND pins are wired to the ESP32’s GND. The ZMPT101B Voltage Sensor’s output analog pin is wired to ESP32’s GPIO35. Similarly, the SCT-013 Current Sensor’s output analog pin is wired to ESP32’s GPIO34. You’ll need two 10K resistors and a single 100-ohm resistor, as well as a 10uF capacitor.

Apart from the circuit, the AC wires that need to be measured for current and voltage are connected to the Voltage Sensor’s input AC Terminal. Similarly, the current sensor clip has no connections, and a single live or neutral wire is put within the clip section, as illustrated in the circuit above.

ESP32 Energy Meter

This project does not require the usage of a 16×2 LCD. We won’t need to connect the LCD because we’ll be using the Blynk application to monitor the ESP32/SCT-013 ZMPT101B/ Energy Meter data. You’ll need a lot of connections if you wish to connect the LCD. Connect the LCD pins 4, 6, 11, 12, 13, and 14 to the D13, D12, D14, D27, D26, and D25 pins on the ESP32. Connect the LCDs’ 1, 5, and 16 pins to GND, and the LCDs’ 2, and 15 pins to 5V VCC. Adjust the LCD Contrast with a 10K Potentiometer connected to Pin 3 of the LCD.


Project PCB Gerber File & PCB Ordering Online

If you don’t want to put the circuit together on a breadboard and instead want a PCB for your project, here is the PCB for you. EasyEDA s online Circuit Schematics & PCB Design tool was used to create the PCB Board for the IoT Energy Meter. The PCB’s front and back sides are shown below.

Download Gerber File: IoT Energy Meter PCB

Now you can visit the NextPCB official website by clicking here: https://www.nextpcb.com/. So you will be directed to NextPCB website.

You can now upload the Gerber File and place an order on the website. The PCBs are in excellent condition. That is why the majority of people entrust NextPCB with their PCB and PCBA needs.


Setting Up Blynk Application

Blynk is a smartphone application that works on Android and iOS smartphones that allow users to operate any IoT-based application. It enables you to design your own IoT application’s graphical user interface. On the Blynk application, we’ll show the data from IoT Energy Meters.

1. So download and install the Blynk Application from Google Play Store. IOS users can download it from the App Store. Once the installation is completed, open the app & sign-up using your Email id and Password.

2. Create a new project from the dashboard and choose ESP32 & Wifi Connection.

3. Finally, drag and drop or add four widgets, assign the variables according to the instructions, and email the authentication code.

4. The authentication code will be mailed to you. This authentication code should be copied. This is what you’ll utilize in your code.


Required Library Installation

1. EmonLib Library

Electricity Energy Meter makes use of the Emonlib Library. EmonLib is a Continuous Monitoring of Electricity Energy that repeats a series of voltage and current measurements every 5 or 10 seconds. EemonLib continuously measures the voltage and current input channels in the background, calculates a true average quantity for each, and then alerts the sketch that the measurements are ready to be read and processed.

Download EmonLib Library

2. Blynk Library

Blynk is the most widely used Internet of Things platform for connecting any gear to the cloud, creating apps to control it, and scaling up your deployed products. With the Blynk Library, you may link over 400 hardware models to the Blynk Cloud, including Arduino, ESP8266, and ESP32.

Download Blynk Library


Source Code/Program – IoT Electricity Energy Meter

You can upload the IoT Electricity Energy Meter Code to the ESP32 Board after adding the above libraries to the Arduino IDE.

Please make adjustments to the WiFi SSID, Password, and Blynk Authentication Token before proceeding.

char auth[] = “605c2d780fd*******d7a31611”;
char ssid[] = “*************************”;
char pass[] = “************************”;

The complete code is given below.

#define BLYNK_PRINT Serial

#include “EmonLib.h” //https://github.com/openenergymonitor/EmonLib
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

EnergyMonitor emon;
#define vCalibration 106.8
#define currCalibration 0.52
BlynkTimer timer;

char auth[] = “*********************”;

char ssid[] = “*********************”;
char pass[] = “*********************3”;

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

void myTimerEvent() {
emon.calcVI(20, 2000);
Serial.print(“Vrms: “);
Serial.print(emon.Vrms, 2);
Serial.print(“V”);
Blynk.virtualWrite(V0, emon.Vrms);
Serial.print(“\tIrms: “);
Serial.print(emon.Irms, 4);
Serial.print(“A”);
Blynk.virtualWrite(V1, emon.Irms);
Serial.print(“\tPower: “);
Serial.print(emon.apparentPower, 4);
Serial.print(“W”);
Blynk.virtualWrite(V2, emon.apparentPower);
Serial.print(“\tkWh: “);
kWh = kWh + emon.apparentPower*(millis()-lastmillis)/3600000000.0;
Serial.print(kWh, 4);
Serial.println(“kWh”);
lastmillis = millis();
Blynk.virtualWrite(V3, kWh);
}

void setup() {
Serial.begin(9600);
emon.voltage(35, vCalibration, 1.7); // Voltage: input pin, calibration, phase_shift
emon.current(34, currCalibration); // Current: input pin, calibration.
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, myTimerEvent);
}

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

Source Code/Program – IoT Electricity Energy Meter with LCD

#include <LiquidCrystal.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>

EnergyMonitor emon;

#define vCalibration 83.3
#define currCalibration 0.50

BlynkTimer timer;

char auth[] = “hsYG_5da4gdP9jZkL18O5RNcJSrBT-Ou”;

char ssid[] = “Alexahome”;
char pass[] = “loranthus”;

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(“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()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
lcd.begin(16, 2);

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(“IoT Energy”);
lcd.setCursor(5, 1);
lcd.print(“Meter”);
delay(3000);
lcd.clear();
}

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

Code Explanation

#define BLYNK_PRINT Serial
#include “EmonLib.h” //https://github.com/openenergymonitor/EmonLib
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

First, we include the ESP32 Board’s required libraries. EmonLib is in charge of retrieving data from both sensors as well as computing RMS and power values. The program is integrated with the Blynk Mobile app using BlynkSimpleEsp32.

EnergyMonitor emon;
#define vCalibration 106.8
#define currCalibration 0.52
BlynkTimer timer;

The emon EnergyMonitor object is created, and the calibration factors are set. After that, the Blynk timer object is constructed to handle data transferring to the Blynk mobile app.

char auth[] = “**********************************”;
char ssid[] = “**********************************”;
char pass[] = “**********************************”;

Then we define the SSID & Password on our local wifi network & insert the authentication code from the Blynk.

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

The millis & kWh values have to be initialized. The kWh starts at 0 and will slowly go up as time goes on.

emon.calcVI(20, 2000);
kWh = kWh + emon.apparentPower * (millis() – lastmillis) / 3600000000.0;

The sensor values are being retrieved and computed. The true power, apparent power, power factor, Vrms, and Irms are calculated using emon.calcVI(20, 2000).

Blynk.virtualWrite(V0, emon.Vrms);
Blynk.virtualWrite(V1, emon.Irms);
Blynk.virtualWrite(V2, emon.apparentPower);
Blynk.virtualWrite(V3, kWh);

We then use Blynk.virtualWrite to send the data to Blynk based on the virtual pins set.

Serial.begin(9600);
emon.voltage(35, vCalibration, 1.7); // Voltage: input pin, calibration, phase_shift
emon.current(34, currCalibration); // Current: input pin, calibration.
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, myTimerEvent);

We configured the Serial baud rate and assigned the current and voltage sensor analog pins to GPIO34 and GPIO35 in the setup function. Then we set the timer to 5000L for a 5-second update time.

Blynk.run();
timer.run();

Inside the loop function we are running the timer and Blynk


Testing: IoT Based Electricity Energy Meter using ESP32 & Blynk

The ESP32 Board will attempt to connect to the wifi network using the SSID and password provided. The following message will appear on the LCD Display. Initially.

ESP32 Energy Meter

The Current and Voltage parameters should be practically zero when no load is connected or when the load is turned off. If it displays a different value, you’ll need to change the calibration factor in the code.

#define vCalibration 106.8
#define currCalibration 0.52
Emonlib Calibration

When the load is connected, the LCD Display will show the voltage and current values, as well as the total kWh units and power consumption.

SCT-013 Energy Meter ESP32
ZMPT101B Energy Meter ESP32

The data from the energy metre is uploaded to the Blynk Application every 5 seconds. The data may be seen on both the Serial Monitor and the Blynk Application.

IoT Based Energy Meter Blynk

Conclusion:

I hope all of you understand how to design an IoT Based Electricity Energy Meter to monitor the electricity consumption of your house. We MATHA ELECTRONICS will be back soon with more informative blogs.

Leave a Reply

Your email address will not be published.