How to Build Wireless Energy Meter With Mobile Billing in Lahore

This guide shows you how to build a wireless energy meter that measures voltage, current, power and energy (kWh) from a real mains load, shows the readings on an LCD, uploads them to the cloud over Wi-Fi, and calculates the electricity bill. It is a student and final year project — a working prototype you can demonstrate with a real load like a light bulb.

Safety warning — read first: this project connects to 220V AC mains electricity, which can kill. Build it only with adult supervision, never touch the PZEM module's mains terminals while power is connected, and enclose the finished meter in an insulated box. Test it first with a small load (a 60W bulb) and never work on live mains wiring alone.

Also important: this is a student prototype, not a certified billing meter. Real electricity billing uses a certified meter from the power company — this project shows how metering and billing work, it does not replace the real meter.

Wireless Energy Meter Circuit Diagram

What This Meter Does

  • Measures voltage (V), current (A), power (W) and energy (kWh) with the PZEM-004T module
  • Shows the readings on a 16x2 LCD
  • Uploads voltage, current, power and energy to ThingSpeak over Wi-Fi
  • Calculates the bill from the energy used and your tariff rate, and shows it on the LCD

Why the ESP32 Only

This project uses the ESP32 only. The PZEM-004T talks over a second hardware serial port (Serial2 on GPIO 16 and 17), and the billing upload needs Wi-Fi. The Arduino Uno has no second hardware serial port and no Wi-Fi, so it cannot run this code. The earlier version of this post listed "ESP32 / Arduino Uno" — that was wrong, and it is corrected here.

Components Required

ComponentSpecificationPrice / link
ESP32 Dev Module30-pin Wi-Fi + Bluetooth boardESP32 30-Pin Wi-Fi Bluetooth Development Board — Rs 1,100
Energy meter modulePZEM-004T (with built-in CT clamp)—
Display16x2 LCD with I2C—
Power supply5V SMPS / 5V USB adapter—
Load for testing60W bulb with holder—
Breadboard + jumper wires——

The PZEM-004T is a module with its own current transformer (CT) clamp — you do not need a separate CT coil. The earlier parts list had a separate CT coil, which was redundant. The PZEM-004T, LCD and 5V supply do not have individual listings in the QKZEE shop — they are available at the Hall Road shop on request.

Wiring Connections

ConnectionPinsNotes
PZEM VCCESP32 5V (VIN)5V supply
PZEM GNDESP32 GND—
PZEM TXESP32 GPIO 16 (RX2)Serial2 receive
PZEM RXESP32 GPIO 17 (TX2)Serial2 transmit
PZEM L terminalMains live (220V)Mains — adult supervision only
PZEM N terminalMains neutral (220V)Mains — adult supervision only
CT clampAround the LIVE wire onlyClamp it around one wire, never both — around both wires it reads zero
LCD SDAGPIO 21I2C data
LCD SCLGPIO 22I2C clock
LCD VCC / GND5V / GNDMost I2C LCD backpacks run on 5V

The PZEM module measures voltage from its L and N terminals and current from the clamp. The clamp must go around the live wire only — if it goes around both the live and neutral wires, the currents cancel out and it reads zero.

How the Meter Works

The PZEM-004T measures the mains voltage directly and the load current through its clamp. It calculates power (voltage x current) and adds up energy over time in kWh. The ESP32 reads these values over Serial2, shows them on the LCD, and every 20 seconds uploads them to ThingSpeak. The bill is simply energy used (kWh) x your tariff rate (Rs per unit) — the tariff is one number in the code that you set to your area's rate.

Arduino Code for Wireless Energy Meter With Mobile Billing

Install these libraries first from the Arduino IDE Library Manager (Sketch - Include Library - Manage Libraries):

  • PZEM004Tv30 by Jakub Mandula
  • LiquidCrystal_I2C by Frank de Brabander (only if you fit the LCD)

Then upload this sketch. Replace the Wi-Fi name, password and ThingSpeak Write API Key with your own (see the ThingSpeak section below). Set TARIFF_PER_UNIT to your area's electricity rate in Rs per kWh.

/*
  Wireless Energy Meter with Mobile Billing
  Reads voltage, current, power and energy from PZEM-004T,
  shows them on a 16x2 LCD, uploads to ThingSpeak,
  and calculates the bill from the tariff rate.
  Board: ESP32 Dev Module. PZEM-004T on Serial2 (RX2 = GPIO 16, TX2 = GPIO 17).
  LCD on I2C (SDA GPIO 21, SCL GPIO 22).
*/

#include <WiFi.h>
#include <HTTPClient.h>
#include <PZEM004Tv30.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define PZEM_RX_PIN 16
#define PZEM_TX_PIN 17

const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";
const char* thingSpeakApiKey = "YOUR_THINGSPEAK_WRITE_API_KEY";
const float TARIFF_PER_UNIT = 35.0; // Rs per kWh - change to your area's rate

PZEM004Tv30 pzem(Serial2, PZEM_RX_PIN, PZEM_TX_PIN);
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  Serial.begin(115200);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Energy Meter");
  lcd.setCursor(0, 1);
  lcd.print("Starting...");

  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWiFi connected");
}

void loop() {
  float voltage = pzem.voltage();
  float current = pzem.current();
  float power = pzem.power();
  float energy = pzem.energy();

  if (isnan(voltage)) {
    Serial.println("PZEM not responding - check wiring!");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("PZEM no reply");
    lcd.setCursor(0, 1);
    lcd.print("Check wiring");
    delay(2000);
    return;
  }

  float bill = energy * TARIFF_PER_UNIT;

  Serial.print("Voltage: ");
  Serial.print(voltage);
  Serial.print(" V | Current: ");
  Serial.print(current);
  Serial.print(" A | Power: ");
  Serial.print(power);
  Serial.print(" W | Energy: ");
  Serial.print(energy);
  Serial.print(" kWh | Bill: Rs ");
  Serial.println(bill);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(voltage, 0);
  lcd.print("V ");
  lcd.print(current, 2);
  lcd.print("A ");
  lcd.print(power, 0);
  lcd.print("W");
  lcd.setCursor(0, 1);
  lcd.print(energy, 3);
  lcd.print("kWh Rs");
  lcd.print(bill, 0);

  // ThingSpeak accepts an update at most every 15 seconds
  static unsigned long lastUpload = 0;
  if (millis() - lastUpload > 20000 && WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    String url = "http://api.thingspeak.com/update?api_key=" + String(thingSpeakApiKey)
               + "&field1=" + String(voltage)
               + "&field2=" + String(current)
               + "&field3=" + String(power)
               + "&field4=" + String(energy);
    http.begin(url);
    Serial.print("ThingSpeak response: ");
    Serial.println(http.GET());
    http.end();
    lastUpload = millis();
  }

  delay(2000);
}

Cloud Integration with ThingSpeak

  1. Create a free account at thingspeak.com and make a new channel with 4 fields: Field 1 = Voltage, Field 2 = Current, Field 3 = Power, Field 4 = Energy (kWh).
  2. Open the channel's API Keys tab and copy the Write API Key.
  3. Paste it into the sketch where it says YOUR_THINGSPEAK_WRITE_API_KEY, along with your Wi-Fi name and password.
  4. Upload the sketch, open the Serial Monitor at 115200 baud, and watch the readings appear. After about 20 seconds, open your ThingSpeak channel — the charts will start filling in.

Firebase and Blynk are also possible for this project, but the sketch above uses ThingSpeak because it is the simplest free option for a student demo: no app to build, just a web dashboard.

Testing the Meter

  1. Test without mains first. Power the ESP32 from USB with nothing connected to the PZEM's L/N terminals. The Serial Monitor should show "PZEM not responding" — that is correct, it proves the error check works.
  2. Test with a small load. With adult supervision, connect a 60W bulb through the meter: mains to PZEM L/N terminals, and the CT clamp around the live wire only. Switch on. A 60W bulb at 220V draws about 0.27A and 60W — your readings should be close to that.
  3. Test the billing. Leave the bulb on for an hour: energy should read about 0.06 kWh, and the bill should read about 0.06 x your tariff. Note that the PZEM's energy counter resets to zero when the module loses power.
  4. Test the cloud upload. Once the readings look right, check your ThingSpeak channel. If the charts stay empty, check the Wi-Fi password and the API key first.

Troubleshooting

  • "PZEM not responding" all the time: check PZEM TX to GPIO 16, RX to GPIO 17, VCC to 5V, GND to GND. The PZEM talks at 9600 baud on Serial2 — the library handles the baud rate, so wiring is the usual cause.
  • Voltage reads 0.00V: the PZEM's L and N terminals are not connected to mains, or the mains switch is off. Never touch these terminals while power is connected.
  • Current reads 0.00A with a load on: the CT clamp is around both wires (live + neutral) — move it so it goes around the live wire only. Or the load is off.
  • Energy resets to zero: normal — the PZEM-004T forgets its energy counter when it loses power. For a demo, note the reading before switching off.
  • LCD shows nothing: check SDA to GPIO 21, SCL to GPIO 22, and the I2C address — most LCD backpacks use 0x27, some use 0x3F. Try the other address if the screen stays blank.
  • Wi-Fi never connects: check the Wi-Fi name and password (both are case-sensitive), and use a 2.4 GHz network — the ESP32 does not connect to 5 GHz Wi-Fi.
  • ThingSpeak response is 0: no internet on the Wi-Fi network, or the API key is wrong. A response of 200 means the update worked.

Applications

  • Student and final year project — a complete IoT metering system
  • Home energy awareness demo — see what each appliance actually uses
  • Small shop load monitoring — track a shop's daily units
  • Final year project base — add daily/monthly totals, alerts above a usage limit, or a mobile app on top

This is a learning prototype, not a certified billing meter. Its readings are good enough for a demo, but real billing always uses a certified meter.

Where to Buy the Components

The ESP32 board is available at QKZEE Technologies, Shop 20, 1st Floor, Al-Khalil Center, Hall Road, Lahore, and online at qkzeetech.com with delivery all over Pakistan — see the link in the components table above. The PZEM-004T module, LCD and 5V supply are available at the Hall Road shop on request.

Still Stuck?

If the PZEM does not respond, or your ThingSpeak charts stay empty, message us — tell us what the Serial Monitor shows (copy the exact lines) and which step you are on, and we will help you find the fault. For anything involving mains wiring, ask an adult or an electrician — do not guess.

Chat on WhatsApp Watch on YouTube

FAQs

Can I use an Arduino Uno for this project?

No. The PZEM-004T needs a second hardware serial port and the billing upload needs Wi-Fi. The Uno has neither. Use the ESP32 as shown in this guide.

Is the PZEM-004T an IC or a module?

It is a module — a complete board with its own current transformer clamp, voltage sensing and serial interface. You do not need a separate CT coil.

Why does my current read zero with the load on?

The CT clamp is almost certainly around both the live and neutral wires. It must go around the live wire only — around both wires the currents cancel out and it reads zero.

Why does the energy reading reset to zero?

The PZEM-004T stores its energy counter in volatile memory, so it forgets the total when it loses power. Note the reading down before switching off.

How is the bill calculated?

Bill = energy used (kWh) x tariff rate (Rs per unit). The tariff is the TARIFF_PER_UNIT number in the code — set it to your area's actual rate. The bill on the LCD updates as energy grows.

Is this meter safe to use on real mains?

Only with adult supervision and an insulated enclosure, and only after testing with a small load like a 60W bulb. Never touch the PZEM's mains terminals while power is connected, and never work on live mains wiring alone.

Conclusion

Building a wireless energy meter with an ESP32 and a PZEM-004T is a strong final year project: it combines mains sensing, serial communication, Wi-Fi, and cloud dashboards in one working system. Follow the wiring above, test with a small load first, and you will have live voltage, current, power, energy and billing figures on ThingSpeak to show your teachers and judges.