Read your electricity meter's LED
Build it step by step
0 of 8 doneBuild the sensor
Wire the photodiode, comparator and pot on a breadboard.
Test with a torch
Pulse a torch on it and see the pulse count rise.
Find your meter constant
Read imp/kWh from the label.
Tape the sensor over the LED
Cover it with black tape and tune the pot.
Fill in the placeholders
Add Wi-Fi and broker details.
Upload
Watch the power change when you switch a heater on.
Compare
Check a known load, such as a 1 kW heater, against the reading.
Log over days
Record standby power at night.
How do you build a read your electricity meter's LED?
A light sensor taped over the meter's pulse LED counts kWh and shows live power without opening anything. You need ESP32 DevKit V1, Photodiode BPW34, LM393 Comparator, Resistor 10 kΩ × 2, Potentiometer 10 kΩ and 5 V 2 A USB adapter. It takes 8 steps and about 120 minutes.
- Level
- Intermediate
- Time
- About 120 min
- Parts
- 6
Parts list
- Development BoardsBuyESP32 DevKit V1 × 1
- SensorsBuyPhotodiode BPW34 × 1
- Integrated CircuitsBuyLM393 Comparator × 1
- PassivesBuyResistor 10 kΩ × 2
- PassivesBuy
- PowerBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| LM393 pin 8 | ESP32 3V3 | Power |
| LM393 pin 4 | ESP32 GND | Ground |
| BPW34 cathode | ESP32 3V3 | Reverse bias |
| BPW34 anode | 10 kΩ resistor to GND, and LM393 pin 3 (IN+A) | Light makes the voltage rise |
| Potentiometer ends | ESP32 3V3 and GND | Reference divider |
| Potentiometer wiper | LM393 pin 2 (IN-A) | Threshold |
| 10 kΩ resistor (pull-up) | 3V3 and LM393 pin 1 (OUT-A) | Open-collector output needs a pull-up |
| LM393 pin 1 | ESP32 GPIO27 | One pulse per meter blink |
| LM393 pins 5, 6 | GND | Unused comparator |
Code
Most electricity meters blink a small LED once for every fixed amount of energy, printed on the label as imp/kWh. Tape the photodiode over that LED with black tape to keep room light out, and tune the potentiometer so the output switches cleanly with each blink; the sensor only looks at a light, so do not open the meter, remove any seal or touch its terminals, and never connect anything to the meter's mains side. Power in watts is 3 600 000 divided by imp/kWh times the seconds between pulses. The reading is good for tracking trends and standby loads but is not a billing record. Use placeholders for the Wi-Fi and broker details, and run the broker on your own network. Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module".
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Counts the meter's pulse LED and publishes power and energy over MQTT. Libraries: PubSubClient.
#include <WiFi.h>
#include <PubSubClient.h>
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const char* MQTT_HOST = "YOUR_BROKER_ADDRESS";
const float IMP_PER_KWH = 1600.0; // read this off your meter label, for example 1600, 3200 or 1000 imp/kWh
const byte PULSE_PIN = 27;
volatile unsigned long pulses = 0, lastPulseMs = 0, intervalMs = 0;
WiFiClient net;
PubSubClient mqtt(net);
unsigned long lastPublish = 0;
void IRAM_ATTR onPulse() {
unsigned long now = millis();
if (now - lastPulseMs > 30) { // ignore bounces within 30 ms
intervalMs = now - lastPulseMs;
lastPulseMs = now;
pulses++;
}
}
void setup() {
Serial.begin(115200);
pinMode(PULSE_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(PULSE_PIN), onPulse, RISING);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) delay(300);
mqtt.setServer(MQTT_HOST, 1883);
}
void loop() {
if (!mqtt.connected()) { mqtt.connect("meter-reader"); }
mqtt.loop();
if (millis() - lastPublish > 10000) {
lastPublish = millis();
noInterrupts(); unsigned long p = pulses, iv = intervalMs, last = lastPulseMs; interrupts();
float kwh = p / IMP_PER_KWH;
float watts = 0;
if (iv > 0 && millis() - last < 120000UL) watts = 3600000.0 / (IMP_PER_KWH * (iv / 1000.0)); // power from the time between pulses
char m[80];
snprintf(m, sizeof(m), "{\"watts\":%.0f,\"kwh_since_start\":%.3f}", watts, kwh);
mqtt.publish("home/meter", m);
Serial.println(m);
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Torch flashes | Pulse count rises |
| Heater on | Power rises to about its rating |
| Everything off | Power falls to the standby level |
| Pulse interval | Shorter at higher power |
If it does not work
No pulses
Adjust the pot and check the photodiode direction.
Too many pulses
Block room light and raise the threshold.
Power wrong
Check the imp/kWh figure on the label.
MQTT silent
Check the broker address and port.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the read your electricity meter's LED?
ESP32 DevKit V1, Photodiode BPW34, LM393 Comparator, Resistor 10 kΩ × 2, Potentiometer 10 kΩ and 5 V 2 A USB adapter.
How long does the read your electricity meter's LED take to build?
About 120 minutes for a intermediate maker, in 8 steps.
How do I know the read your electricity meter's LED works?
Torch flashes: Pulse count rises. Heater on: Power rises to about its rating. Everything off: Power falls to the standby level.
No pulses: what should I check?
Adjust the pot and check the photodiode direction.
Too many pulses: what should I check?
Block room light and raise the threshold.
Power wrong: what should I check?
Check the imp/kWh figure on the label.
MQTT silent: what should I check?
Check the broker address and port.
