Components · 10 min read

PZEM-004T ESP32 Energy Meter: Voltage, Current, Power and kWh

PZEM-004T v3 with ESP32: voltage, current, power, kWh, frequency and power factor. Modbus-RTU wiring, CT direction, daily cost dashboard and mains safety.

Paired with an ESP32, the PZEM-004T becomes an energy meter that lets you watch the electricity use of a socket, a water heater or a whole flat from your phone. This small module from Peacefair measures mains voltage, current, active power, energy (kWh), frequency and power factor with its own chip and delivers the results over an isolated serial line using the Modbus-RTU protocol. So you don't deal with the measurement maths; the ESP32 simply reads finished values.

In this guide we'll go step by step through the PZEM-004T v3's measuring range and accuracy, how to connect the mains side and the current transformer, how to match the module's TTL interface to the ESP32's 3.3 V, a first reading with the PZEM004Tv30 library, and a web dashboard showing daily consumption and cost. Keep one thing in mind from the start: one side of this module runs on 220–240 V, and the safety rules are the most important part of this article.

What is the PZEM-004T v3 and what does it measure?

The module comes in two versions. On the 10 A version the load current flows through a shunt resistor on the board, so the live wire runs through the module; it suits small appliances. On the 100 A version current is measured with a current transformer (CT) that goes around the cable without cutting it; that's the one to choose for a whole house or an electric heater. In both versions the measuring chip takes its power from the mains, while the TTL side going to the ESP32 is isolated from the mains by optocouplers. The energy counter is kept in the module's non-volatile memory, so the kWh value survives a power cut.

MeasurementRangeResolutionAccuracy
Voltage80–260 V AC0.1 V0.5%
Current10 A version 0–10 A, 100 A version 0–100 A0.001 A0.5%
Active power0–2.3 kW (10 A) / 0–23 kW (100 A), from 0.4 W0.1 W0.5%
Energy0–9999.99 kWh1 Wh0.5%
Frequency45–65 Hz0.1 Hz0.5%
Power factor0.00–1.000.011%
CommunicationTTL UART, 9600 baud, 8N1, Modbus-RTUAddress 0x01–0xF7, general address 0xF8Optocoupler isolated

Power factor is confusing at first. With resistive loads such as a kettle or an electric heater, active power equals voltage times current and the power factor reads 1.00. With a phone charger, an LED lamp or a fridge motor, the current doesn't flow exactly in step with the voltage; then active power = V × I × PF. For example, a device drawing 0.5 A at 230 V takes 115 VA of apparent power, but if the PF is 0.60 the power actually used is only 69 W. That active power is what turns into the kWh on your bill. See our electrical power calculation guide for the formulas in detail.

The mains side of the PZEM-004T runs on 220–240 V and can kill you if you touch it. Make every connection with the breaker off and confirm the power is really off with a voltage tester. Put the module in a closed, insulated enclosure with no exposed terminals; a small fuse (e.g. 0.5 A) on the voltage sense wires is a good extra precaution. If you need to work in the consumer unit, have an electrician do it. Even though the TTL side is isolated, the clearances on the board are small: don't touch the board while it's live, and keep your USB-connected laptop away from the mains wiring.

Mains wiring and which way the current transformer goes

TerminalConnects toNote
Voltage input (L, N)Live and neutral of the line being measuredSupplies both the voltage measurement and the module itself
CT input (100 A version)The two leads of the current transformerDon't shorten or extend the CT lead; it's factory calibrated
Current terminals (10 A version)The live wire passes through the module in series10 A maximum; use the 100 A version for bigger loads
TTL (5V, RX, TX, GND)ESP32, Arduino or PicoIsolated from the mains by optocouplers
  • Pass only one conductor through the CT: Only the live (L) wire should go through the transformer. If live and neutral go through together, their currents cancel and the module reads 0 A; that's why you can't clamp the CT over the outer sheath of a multi-core cable.
  • Close the ring fully: On split-core CTs, the faces of the two halves must be clean and the latch fully seated; any gap lowers the reading.
  • Direction: The PZEM-004T doesn't report current direction; the power and energy registers are unsigned and never show negative values. If the CT has an arrow, point it toward the load so your readings stay consistent, and check power and power factor with a known resistive load (e.g. a 2000 W heater); if the power is far too low or the PF far from 1, flip the CT and try again.
  • Solar warning: Without direction information, the PZEM-004T can't separate imported from exported energy in a grid-tied solar system.
  • Single phase: The module measures one phase only; a three-phase installation needs one module per phase.

TTL (UART) wiring: ESP32, Arduino and Pico

PZEM pinESP32Arduino UnoRaspberry Pi Pico
5V3V3 (easiest) or VIN 5 V + divider on the TX line5V3V3(OUT)
GNDGNDGNDGND
TXGPIO 16 (RX2)D2 (SoftwareSerial RX)GP1 (UART0 RX)
RXGPIO 17 (TX2)D3 (SoftwareSerial TX)GP0 (UART0 TX)

The 5V pin on the module's TTL side doesn't power the measuring chip, only the optocouplers, and the PZEM's TX output is pulled up to that voltage. So if you feed this pin from 5 V, the TX line sends 5 V into the ESP32, whose pins are built for 3.3 V. The easiest fix is to feed the pin straight from the ESP32's 3V3 output: TX then becomes 3.3 V too and most modules communicate without trouble. If every value comes back as NaN at 3.3 V, the problem is usually on the RX side; on v3.0 boards, soldering a second 1 kΩ in parallel with the 1 kΩ resistor (R8) in front of the RX optocoupler drives it hard enough. If you'd rather not solder, power the 5V pin from VIN and put a 1 kΩ / 2 kΩ voltage divider on the PZEM's TX line. The Arduino Uno already runs at 5 V, so it needs no changes.

Modbus-RTU: how the ESP32 talks to the PZEM

In Modbus-RTU the ESP32 is the side that asks (master) and the PZEM is the side that answers (slave). At 9600 baud the ESP32 sends an 8-byte request: module address, function code 0x04 (read input registers), start register 0x0000, number of registers 10, and a two-byte CRC-16 checksum. Using the general address 0xF8 for a single module, the request is F8 04 00 00 00 0A 64 64. The PZEM replies with 25 bytes: address, 0x04, data byte count (20), the 20 bytes of the ten registers, and the CRC. 32-bit values are split over two registers with the low 16 bits first. The library does all of this for you, but knowing the structure helps when you write your own code on a Pico or another board. For serial basics, see our UART serial communication guide.

RegisterContentUnit and example
0x0000Voltage0.1 V; 2301 → 230.1 V
0x0001–0x0002Current (low 16 bits first)0.001 A; 1234 → 1.234 A
0x0003–0x0004Active power0.1 W; 2805 → 280.5 W
0x0005–0x0006Energy1 Wh; 12345 → 12.345 kWh
0x0007Frequency0.1 Hz; 500 → 50.0 Hz
0x0008Power factor0.01; 98 → 0.98
0x0009Alarm status0xFFFF alarm, 0x0000 none
Holding 0x0001 / 0x0002Power alarm threshold / Modbus addressRead with 0x03, written with 0x06; energy reset command 0x42

Step by step: first reading with ESP32 (PZEM004Tv30 library)

  1. In the Arduino IDE, open the Library Manager, search for PZEM004Tv30 and install the library by Jakub Mandula.
  2. With the breaker off, wire the mains side according to the table above, put the current transformer on the live wire only and close the enclosure.
  3. On the TTL side, connect 5V to the ESP32's 3V3, GND to GND, TX to GPIO 16 and RX to GPIO 17.
  4. Upload the code below and open the Serial Monitor at 115200 baud.
  5. Switch the breaker on: values should appear within a few seconds. Because the measuring chip is powered from the mains, the module won't answer at all until L and N are live.
  6. Run an appliance whose power you know (such as a kettle) and compare the reading with the power on its label.
C++ (Arduino IDE)
1#include <PZEM004Tv30.h>
2
3#define PZEM_RX 16                     // ESP32 RX2 ← PZEM TX
4#define PZEM_TX 17                     // ESP32 TX2 → PZEM RX
5
6PZEM004Tv30 pzem(Serial2, PZEM_RX, PZEM_TX);   // 9600 baud, Modbus-RTU, adres 0xF8 / address 0xF8
7
8void setup() {
9  Serial.begin(115200);
10  Serial.printf("PZEM adresi / address: 0x%02X\n", pzem.readAddress());
11}
12
13void loop() {
14  float volts = pzem.voltage();        // V
15  float amps = pzem.current();         // A
16  float watts = pzem.power();          // W (aktif güç / active power)
17  float kwh = pzem.energy();           // kWh (kalıcı sayaç / non-volatile counter)
18  float hertz = pzem.frequency();      // Hz
19  float pfac = pzem.pf();              // güç faktörü / power factor
20
21  if (isnan(volts)) {                  // cevap yok: kablo, besleme ya da RX/TX / no reply: wiring, supply or RX/TX
22    Serial.println("PZEM yanit vermiyor / PZEM not responding");
23  } else {
24    Serial.printf("%.1f V | %.3f A | %.1f W | %.3f kWh | %.1f Hz | PF %.2f\n",
25                  volts, amps, watts, kwh, hertz, pfac);
26  }
27  delay(2000);
28}

The library doesn't query the module on every function call: it reads all ten registers in a single Modbus request and caches them for 200 ms, so reading six values in a row is just one exchange. If the module doesn't answer, the functions return NaN (not a number), which is why we check the value with isnan() before using it. The address printed at start-up is the real address of the module reached through the general address (usually 0x01 from the factory). The energy value is the total accumulated since the module first ran or was last reset.

PZEM-004T with Arduino Uno

The Uno's single hardware serial port is busy talking to the computer, so we connect the PZEM to D2 and D3 with SoftwareSerial; 9600 baud is a comfortable speed for this method. You can wire the module's 5V pin straight to the Uno's 5V, and no extra parts are needed for level matching. If you want to see the values on the bench, it's easy to extend the code with an I2C LCD display.

C++ (Arduino IDE)
1#include <PZEM004Tv30.h>
2#include <SoftwareSerial.h>
3
4SoftwareSerial pzemSerial(2, 3);       // RX = D2 ← PZEM TX, TX = D3 → PZEM RX
5PZEM004Tv30 pzem(pzemSerial);          // Uno'da PZEM'in TTL tarafı 5V'tan beslenir / TTL side powered from 5V
6
7void setup() {
8  Serial.begin(115200);
9}
10
11void loop() {
12  float volts = pzem.voltage();
13  if (isnan(volts)) {
14    Serial.println(F("PZEM yanit vermiyor / not responding"));
15  } else {
16    Serial.print(volts, 1);              Serial.print(F(" V  "));
17    Serial.print(pzem.current(), 3);     Serial.print(F(" A  "));
18    Serial.print(pzem.power(), 1);       Serial.print(F(" W  "));
19    Serial.print(pzem.energy(), 3);      Serial.print(F(" kWh  "));
20    Serial.print(pzem.frequency(), 1);   Serial.print(F(" Hz  PF "));
21    Serial.println(pzem.pf(), 2);
22  }
23  delay(2000);
24}

Daily consumption and cost on a web dashboard

The module's kWh counter only goes up. To get daily consumption we store the counter value as the starting point at the first reading after the day changes: today's consumption = current counter − counter at start of day, and cost = today's kWh × price per kWh. For example, a 2000 W heater running for 3 hours uses 2 kW × 3 h = 6 kWh; at $0.17 per kWh that's about $1.02. Put the unit price from your bill, taxes included, into PRICE_PER_KWH. The code below starts a small web server on the ESP32; the main page fetches JSON from /data every two seconds and updates eight tiles.

C++ (Arduino IDE)
1#include <WiFi.h>
2#include <WebServer.h>
3#include <Preferences.h>
4#include <time.h>
5#include <PZEM004Tv30.h>
6
7const char* WIFI_SSID = "MonWiFi";                     // Wi-Fi adın / your Wi-Fi name
8const char* WIFI_PASS = "MotDePasse123";               // Wi-Fi şifren / your Wi-Fi password
9const float PRICE_PER_KWH = 0.20;                      // kendi kWh fiyatın / your price per kWh
10const char* TZ_INFO = "CET-1CEST,M3.5.0,M10.5.0/3";    // Paris, Berlin, Madrid, Roma; Türkiye: "<+03>-3"
11
12PZEM004Tv30 pzem(Serial2, 16, 17);                     // RX2 = 16 ← PZEM TX, TX2 = 17 → PZEM RX
13WebServer server(80);
14Preferences prefs;
15
16float volts = NAN, amps, watts, kwh, hertz, pfac;      // son ölçümler / latest readings
17float dayStartKwh = -1;                                // gün başındaki sayaç / counter at the start of the day
18int savedDay = -1;                                     // yılın günü (0–365) / day of the year
19unsigned long lastRead = 0;
20
21const char PAGE[] PROGMEM = R"rawliteral(
22<!doctype html><html><head><meta charset="utf-8">
23<meta name="viewport" content="width=device-width, initial-scale=1">
24<title>PZEM-004T</title>
25<style>
26body{font-family:sans-serif;margin:16px;background:#f4f6f8}
27.g{display:grid;grid-template-columns:repeat(2,1fr);gap:10px;max-width:420px}
28.c{background:#fff;border-radius:10px;padding:12px;color:#555}
29.c b{display:block;font-size:26px;color:#111}
30</style></head><body>
31<h2>PZEM-004T</h2>
32<div class="g">
33<div class="c">V<b id="v">-</b></div><div class="c">A<b id="i">-</b></div>
34<div class="c">W<b id="p">-</b></div><div class="c">kWh<b id="e">-</b></div>
35<div class="c">Hz<b id="f">-</b></div><div class="c">PF<b id="pf">-</b></div>
36<div class="c">Today kWh<b id="today">-</b></div><div class="c">Today cost<b id="cost">-</b></div>
37</div>
38<script>
39async function u(){try{const d=await (await fetch('/data')).json();
40for(const k in d){const el=document.getElementById(k);if(el)el.textContent=d[k];}}catch(e){}}
41setInterval(u,2000);u();
42</script></body></html>
43)rawliteral";
44
45void readPzem() {
46  volts = pzem.voltage();
47  amps = pzem.current();
48  watts = pzem.power();
49  kwh = pzem.energy();
50  hertz = pzem.frequency();
51  pfac = pzem.pf();
52}
53
54// Gün değişince sayacın o anki değerini başlangıç olarak sakla / store the counter when the day changes
55void checkNewDay() {
56  struct tm now;
57  if (isnan(kwh) || !getLocalTime(&now, 50)) return;   // ölçüm ya da saat yoksa bekle / wait for data and time
58  if (now.tm_yday != savedDay || dayStartKwh < 0 || kwh < dayStartKwh) {
59    savedDay = now.tm_yday;
60    dayStartKwh = kwh;
61    prefs.putInt("day", savedDay);                     // elektrik kesilse de kalır / survives a power cut
62    prefs.putFloat("start", dayStartKwh);
63  }
64}
65
66void handleRoot() {
67  server.send_P(200, "text/html", PAGE);
68}
69
70void handleData() {
71  if (isnan(volts)) {
72    server.send(503, "application/json", "{\"error\":\"PZEM\"}");
73    return;
74  }
75  float today = dayStartKwh < 0 ? 0 : kwh - dayStartKwh;
76  char json[220];
77  snprintf(json, sizeof(json),
78           "{\"v\":\"%.1f\",\"i\":\"%.3f\",\"p\":\"%.1f\",\"e\":\"%.3f\",\"f\":\"%.1f\",\"pf\":\"%.2f\","
79           "\"today\":\"%.3f\",\"cost\":\"%.2f\"}",
80           volts, amps, watts, kwh, hertz, pfac, today, today * PRICE_PER_KWH);
81  server.send(200, "application/json", json);
82}
83
84void setup() {
85  Serial.begin(115200);
86  prefs.begin("pzem", false);
87  savedDay = prefs.getInt("day", -1);
88  dayStartKwh = prefs.getFloat("start", -1);
89
90  WiFi.mode(WIFI_STA);
91  WiFi.begin(WIFI_SSID, WIFI_PASS);
92  while (WiFi.status() != WL_CONNECTED) {
93    delay(500);
94    Serial.print(".");
95  }
96  Serial.print("\nPanel: http://");
97  Serial.println(WiFi.localIP());
98
99  configTzTime(TZ_INFO, "pool.ntp.org");               // NTP ile saat / time over NTP
100  server.on("/", handleRoot);
101  server.on("/data", handleData);
102  server.begin();
103}
104
105void loop() {
106  server.handleClient();
107  if (millis() - lastRead >= 2000) {                   // 2 sn'de bir ölç / measure every 2 s
108    lastRead = millis();
109    readPzem();
110    checkNewDay();
111  }
112}

After uploading, open the address printed in the Serial Monitor on a phone connected to the same Wi-Fi. The time comes from NTP; remember to put your own time zone in the TZ_INFO line, or the day will roll over at some hour other than midnight. The start-of-day value is written to flash with Preferences only once a day, so the memory doesn't wear out and the daily total survives an ESP32 restart; since the PZEM's counter is non-volatile too, the calculation stays consistent after a power cut. You can apply the same method to the first day of the month for monthly consumption, or store the readings permanently by sending them to an ESP32 MySQL database.

Changing the address, power alarm and resetting the kWh counter

The general address 0xF8 reaches whatever is on the bus, so it only works with a single module. If, for example, you'll use two modules to measure the kitchen and the washing machine circuits separately, connect each one on its own and give it a different address (0x01–0xF7) with the code below; the address is kept in the module's memory. Then you create a separate object with its own address for each module, for example PZEM004Tv30 kitchen(Serial2, 16, 17, 0x01). In the same code, setPowerAlarm() turns on the module's alarm bit above the wattage you set, and resetEnergy() clears the kWh counter; uncomment that line only when you really want to reset it.

C++ (Arduino IDE)
1#include <PZEM004Tv30.h>
2
3// Hatta yalnız bu modül bağlıyken çalıştır / run with only this module on the bus
4PZEM004Tv30 pzem(Serial2, 16, 17);
5const uint8_t NEW_ADDR = 0x02;         // 0x01–0xF7 arası / between 0x01 and 0xF7
6
7void setup() {
8  Serial.begin(115200);
9  Serial.printf("Mevcut adres / Current address: 0x%02X\n", pzem.readAddress());
10  if (pzem.setAddress(NEW_ADDR)) {
11    Serial.printf("Yeni adres / New address: 0x%02X\n", pzem.readAddress());
12  }
13  pzem.setPowerAlarm(2000);            // 2000 W üstünde alarm biti / alarm bit above 2000 W
14  // pzem.resetEnergy();               // kWh sayacını sıfırlar / resets the kWh counter
15}
16
17void loop() {
18  Serial.printf("%.1f W, alarm: %s\n", pzem.power(), pzem.getPowerAlarm() ? "VAR / ON" : "yok / off");
19  delay(2000);
20}

PZEM-004T with Raspberry Pi Pico and MicroPython

In MicroPython you don't need a ready-made library: we'll build the 8-byte request described above ourselves, calculate the CRC-16 and split the 25-byte reply into ten registers with struct.unpack. Connect the module's 5V pin to the Pico's 3V3(OUT), TX to GP1 and RX to GP0. If the reply's CRC doesn't match, the function returns None, so corrupted values from a noisy line never get printed.

MicroPython
1from machine import UART, Pin
2import struct, time
3
4# GP0 (TX) → PZEM RX, GP1 (RX) ← PZEM TX, PZEM 5V pini → 3V3(OUT)
5uart = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1), timeout=300)
6ADDR = 0xF8                                   # tek modül için genel adres / general address for one module
7
8def crc16(data):
9    # Modbus CRC-16 (polinom / polynomial 0xA001)
10    crc = 0xFFFF
11    for b in data:
12        crc ^= b
13        for _ in range(8):
14            crc = (crc >> 1) ^ 0xA001 if crc & 1 else crc >> 1
15    return crc
16
17def read_pzem():
18    req = bytes([ADDR, 0x04, 0x00, 0x00, 0x00, 0x0A])   # 0x0000'dan 10 yazmaç oku / read 10 input registers
19    c = crc16(req)
20    req += bytes([c & 0xFF, c >> 8])                     # CRC: önce düşük bayt / low byte first
21    while uart.any():
22        uart.read()                                      # eski baytları at / drop stale bytes
23    uart.write(req)
24    resp = uart.read(25)                                 # 3 + 20 veri + 2 CRC / 3 + 20 data + 2 CRC
25    if not resp or len(resp) != 25:
26        return None
27    if crc16(resp[:-2]) != resp[-2] | (resp[-1] << 8):
28        return None                                      # bozuk cevap / corrupted reply
29    r = struct.unpack('>10H', resp[3:23])
30    return {
31        'V': r[0] / 10,
32        'A': (r[1] | r[2] << 16) / 1000,                 # 32 bit: önce düşük kelime / low word first
33        'W': (r[3] | r[4] << 16) / 10,
34        'kWh': (r[5] | r[6] << 16) / 1000,
35        'Hz': r[7] / 10,
36        'PF': r[8] / 100,
37        'alarm': r[9] == 0xFFFF,
38    }
39
40while True:
41    d = read_pzem()
42    print(d if d else "PZEM yanit vermiyor / not responding")
43    time.sleep(2)

PZEM-004T project ideas

  • Smart plug with metering: Add a PZEM to the ESP32 smart plug project and see how much the appliance you switch actually uses.
  • Overload warning: Sound a buzzer or send a notification when the power alarm trips; to cut the load, use a solid-state relay or contactor rated for the current.
  • Laundry done alert: Send a Telegram message when the washing machine stays below 5 W for two minutes.
  • Home Assistant energy dashboard: Send the values to Home Assistant over MQTT, or use ESPHome's built-in PZEM support.
  • Standby power hunt: Measure how much the TV, router and chargers waste in total overnight.
  • Heater versus heat pump: Heat the same room both ways and compare daily kWh and cost side by side.

Common problems and fixes

SymptomLikely causeFix
Every value is NaNNo mains voltage connected, RX/TX swapped or TTL side not poweredMake sure L and N are live, swap TX and RX, check 5V and GND
Occasional NaNRX optocoupler driven weakly at 3.3 V, or long wiresAdd 1 kΩ in parallel with R8 or use 5 V + TX divider, shorten the TTL wires
Voltage fine, current 0Live and neutral both through the CT, CT not closed or load too smallPass only the live wire, latch the ring, test with a load above 10 W
Current present, power lower than expectedLow power factor of the load, or the CT may be reversedCheck that PF is close to 1 with a resistive load; flip the CT if needed
Two modules give mixed-up valuesBoth on the same or the general address (0xF8)Connect each one alone and give it its own address
Daily total resets at the wrong timeWrong TZ_INFO time zone or NTP unreachableFix the time zone, check the Wi-Fi connection
Check the accuracy with a clamp meter or a resistive load whose rating you know: a 2000 W heater draws about 8.7 A at 230 V. Since the PZEM is factory calibrated, the error is usually under 1%; if you see a big difference, first check that the CT is fully closed and only one wire passes through it. If measuring current alone is enough, or you're working with DC, the ACS712 current sensor is a simpler option, but you'll have to calculate power and power factor yourself.

The PZEM-004T is both the most accurate and the easiest way to measure household electricity: the module does the maths, and you only take care of a safe enclosure, a correctly fitted current transformer and a few lines of code. To brush up on the basics of current and voltage, read our AC vs DC current guide. In the BlueGrays app you'll find step-by-step ESP32 projects for Wi-Fi connection, web server, live dashboard with WebSocket and NTP time, with circuit diagrams and code, so you can grow this energy meter to fit your own home.

Frequently asked questions

Does the PZEM-004T work with an ESP32 at 3.3 V?

Yes, most modules communicate fine when the 5V pin is fed from the ESP32's 3V3 output, which also keeps the TX line at 3.3 V. If you get NaN values, the RX optocoupler isn't driven hard enough; adding 1 kΩ in parallel with resistor R8, or powering the module from 5 V with a voltage divider on TX, solves it.

Why does my PZEM-004T always show NaN or 0?

NaN means the module isn't answering at all: the usual causes are no mains voltage on L and N, TX and RX swapped, or the TTL side not powered. If voltage is correct but current reads 0, live and neutral are passing through the CT together or the CT isn't fully closed.

Which way should the PZEM-004T current transformer go?

Only the live wire should pass through the CT; if it has an arrow, point it toward the load. The PZEM-004T doesn't report current direction and never shows negative power, so the best way to check the orientation is to confirm that power and power factor come out close to the expected values with a known resistive load.

Can the PZEM-004T measure solar production and exported energy?

A single PZEM-004T can't tell them apart: its power and energy registers are unsigned, so it shows a positive value whichever way the current flows. You can measure production by putting a separate module on the inverter output, but separating imported from exported energy needs a bidirectional meter.

What's the difference between the 10 A and 100 A PZEM-004T?

On the 10 A version, current flows through a shunt resistor on the board, so you wire the live conductor through the module in series and can measure up to 2.3 kW. The 100 A version measures current with a current transformer fitted without cutting the cable and goes up to 23 kW; it's the better and safer choice for a whole house or big loads like heaters.

How do I reset the PZEM-004T kWh counter?

The library's resetEnergy() function sends command 0x42 to the module and clears the kWh counter. Because the counter lives in the module's non-volatile memory, it doesn't reset by itself after a power cut. For daily or monthly consumption it's safer to store the value at the start of the period and calculate the difference than to reset the counter.

See all projects
ESP32 Wi-Fi STA Connection (with LCD Screen)
ES-25Advanced

ESP32 Wi-Fi STA Connection (with LCD Screen)

In this project, we connect the ESP32 to the home Wi-Fi network in Station (STA) mode in a secure, fault-tolerant manner. We store the SSID and password in a separate secrets.h file to prevent leaking to Git, set up an auto-reconnect mechanism, and display the RSSI signal level and IP address on an I2C LCD screen. The internal LED works as a status indicator. It is a production-grade connection manager.

4.4(21)
38
ESP32 Asynchronous Web Server (with IP Display on LCD)
ES-27Advanced

ESP32 Asynchronous Web Server (with IP Display on LCD)

In this project, we’re turning the ESP32 into an asynchronous web server that you can control from your phone or computer on the same Wi-Fi network. Thanks to the ESPAsyncWebServer library, the server can process multiple requests simultaneously (unlike the classic WebServer.h, which blocks on a single request). You’ll be able to open the ESP32’s IP address in a browser and click the ON/OFF buttons (the /on and /off routes) to turn the LED connected to GPIO 5 on and off.

4.8(16)
26
ESP32 WebSocket Counter (2 Buttons + LCD + Real-Time Web)
ES-28Advanced
Premium

ESP32 WebSocket Counter (2 Buttons + LCD + Real-Time Web)

In this project, two buttons wired to the ESP32 (GPIO 5 counts up, GPIO 4 counts down) change a counter. The value updates instantly both on a 16x2 I2C LCD and, through the WebSocket support of ESPAsyncWebServer, in every connected browser without reloading the page. Instead of HTTP polling a single persistent connection is used, and the ESP32 sends the new value to everyone with ws.textAll().

4.5(14)
23
Real-Time Clock from the Internet via ESP32 NTP
ES-26Advanced
Premium

Real-Time Clock from the Internet via ESP32 NTP

The ESP32 connects to Wi-Fi and fetches the real time from NTP (Network Time Protocol) servers with millisecond precision. configTzTime() applies the Turkey time zone (TRT, UTC+3) automatically, and in countries with daylight saving time the DST switch is handled by a POSIX TZ string. The time is printed both to the Serial Monitor and to an optional I2C LCD.

4.5(13)
22
Digital Voltmeter with LCD Display
AR-56Intermediate
Premium

Digital Voltmeter with LCD Display

Find out how much voltage a battery or power adapter gives with a meter you built yourself.

4.5(27)
36
Lighting 220V Bulb with Push Button
AR-19Advanced
Premium

Lighting 220V Bulb with Push Button

As long as you hold the button, a real 220-volt bulb stays lit, and it goes out the moment you let go.

4.4(30)
38
Lighting 220V Bulb with Remote Control
AR-21Advanced
Premium

Lighting 220V Bulb with Remote Control

Switch a real light bulb in your home on and off with a TV remote, without getting up from the sofa.

4.4(23)
31
ESP32 Smart Lighting (PIR + LDR + Relay + OLED)
ES-37Advanced
Premium

ESP32 Smart Lighting (PIR + LDR + Relay + OLED)

With an ESP32, a PIR motion sensor, an LDR light sensor and a relay module, we turn your hallway, bathroom or pantry into smart lighting. If the room is already bright, the light stays off even when there is motion, so it never wastes energy during the day. The light stays on for 30 seconds, and the time extends automatically while motion continues.

4.3(6)
11