IoT Smart Energy Meter using NodeMCU ESP8266

IoT Smart Energy Meter using NodeMCU:
Conventional energy meter which we use in our households to measure Energy consumption is an offline device, so it has to be monitored manually. But nowadays there are Smart Energy Meters available in the market whose readings can be monitored from anywhere using the internet and not only energy consumption but we can monitor multiple parameters such as voltage, current, power factor, frequency, etc. on laptop or mobile using IoT.
Here we building Smart Energy Meter using IoT. Here we will use PZEM-004T AC multifunction Electric Energy Metering Power Monitor module to measure the parameters and will use NodeMCU ESP8266 to post the data to an HTML Webpage.

Materials Required:
1. NodeMCU ESP8266
2. PZEM-004T module
3. CT coil

Working of PZEM-004T Module:
PZEM-004TAC Module is used for measuring AC voltage, current, active power, frequency, power factor, and active energy. The module gives output through TTL terminals, which can be read by various microcontrollers for further applications.

Technical Features:
1. Voltage Measuring Range: 80-260 VAC
2. Current Measuring Range: 0-100 Amp
3. Active Power Measuring Range: 0-23KW
4. Power Factor Measuring Range: 0-1
5. Frequency Measuring Range: 45-65 Hz
6. Module Working Voltage: 5V DC
7. Output Interface: TTL

Pin Description:

VCC: 5V DC Input supply for the Module
GND: Ground electrical Reference
TX: UART Transmission pin for Data
RX: UART Receiver pin for Data.

IoT Energy Meter Circuit Diagram:

Programming Code Explanation:
After the successful completion of the hardware setup, now it’s time to program NodeMCU. Complete code for this smart electricity meter along with the video is given at the end of this tutorial. The stepwise description of the code is given below.

To upload code into NodeMCU using Arduino IDE, follow the steps below:
1. Open Arduino IDE, then go to File–>Preferences–>Settings.
2. After installation is complete, go to Tools ->Board -> and select NodeMCU 1.0(ESP-12E Module). Now you can program NodeMCU with Arduino IDE.

Ater the above setup for programming NodeMCU using Arduino IDE, upload the complete code into ESP8266 NodeMCU. The stepwise explanation of the complete code is given below.

Here ESP8266 board library is used for NodeMCU and PZEM004Tv30.h is used for the Energy monitoring module which can be downloaded from here.

Testing the IoT based energy meter using NodeMCU:
After complete connections and hardware setup, just upload the code into NodeMCU and open the IP address printed in the serial monitor. You will see something like below.

Here we have attached an AC bulb to monitor the energy consumed by the bulb along with other parameters like voltage, current, power factor, etc.

PZEM-004T energy power module details:
1. Brand: Peacefair
2. Model: PZEM-004T
3. Operating Voltage: 80-260VAC
4. Test Voltage: 80-260VAC
5. Rated Current: 100A
6. Rated power: 100A / 22000W
7. Operating frequency: 45-65Hz
8. Measurement accuracy: 1.0

1. Electrical parameter measurement function (voltage, current, active power, power).
2. The power button clear function.
3. Power-down data storage function (cumulative power down before saving).
4. PC PC display function (display voltage, current, active power, power).
5. The serial communication function (comes with TTL serial interface, through various terminals to communicate with the adapter plate, read, and set the parameters).

#include <PZEM004Tv30.h>
PZEM004Tv30 pzem(D1,D2);  //RX/TX
const char* ssid = "androiderode";//Replace with your network SSID
const char* password = "erode123";//Replace with your network password

ESP8266WebServer server(80);
float voltage,current,pf,frequency,power;
String page = "";
void setup()
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
server.on("/", []()
page = "<html><head><title>Smart Energy Meter using IoT</title></head><style type=\"text/css\">";
page += "table{border-collapse: collapse;}th {background-color:  green ;color: white;}table,td {border: 4px solid black;font-size: x-large;";
page += "text-align:center;border-style: groove;border-color: rgb(255,0,0);}</style><body><center>";
page += "<h1>Smart Energy Meter using IoT</h1><br><br><table style=\"width: 1200px;height: 450px;\"><tr>";
page += "<th>Parameters</th><th>Value</th><th>Units</th></tr><tr><td>Voltage</td><td>"+String(voltage)+"</td><td>Volts</td></tr>";
page += "<tr><td>Current</td><td>"+String(current)+"</td><td>Amperes</td></tr><tr><td>Power Factor</td><td>"+String(pf)+"</td><td>XXXX</td>";
page += "<tr><td>Power</td><td>"+String(power)+"</td><td>Watts</td></tr><tr>";
page += "</tr><tr><td>Frequency</td><td>"+String(frequency,1)+"</td><td>Hz</td></tr>";
page += "<meta http-equiv=\"refresh\" content=\"3\">";
server.send(200, "text/html", page);
void loop()
voltage = pzem.voltage();
current = pzem.current();
power = pzem.power();
frequency = pzem.frequency();
pf =;

Subramanian MK, currently serving as a workshop instructor at Sakthi Polytechnic College, Erode Tamil Nadu. With a career spanning 25 + years, Subramanian MK has dedicated himself to advancing knowledge in Electronics and Communication Engineering (ECE). His passion for exploring new technologies has led to the development of numerous projects, showcasing expertise in IoT and PCB design.

Articles: 504

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Hi, How can I help you?