A watt hour meter tracks energy consumption in real time, logging watts, watt-hours, and cumulative kWh. Building a DIY energy logger helps you understand electricity usage patterns, identify power-hungry devices, and optimise your energy costs. This guide covers building an Arduino-based energy logger using the INA219 (for DC) or ZMPT101B+ACS712 (for AC) with SD card data logging.
What Is a Watt Hour Meter?
A watt-hour meter measures energy (the product of power and time):
Energy (Wh) = Power (W) x Time (hours)
Energy (Wh) = Voltage (V) x Current (A) x Time (hours)
Digital measurement:
Sample V and I every 100ms
Wh += (V x I) x (0.1s / 3600)
Example: Monitor a 12V battery system
11:00 - 11:30: Solar charging at 5A → 12V x 5A x 0.5h = 30Wh IN
11:30 - 13:00: Load drawing 2A → 12V x 2A x 1.5h = 36Wh OUT
Net: -6Wh (more consumed than generated)
Hardware Components
- DC monitoring: INA219 module (measures V, I, P simultaneously via I2C)
- AC monitoring: ZMPT101B (voltage) + ACS712 (current) for 230V Indian mains
- Display: 0.96″ or 1.3″ OLED for real-time readings
- Data logging: SD card module for long-term energy data recording
- Controller: Arduino Nano (simple) or ESP32 (WiFi data upload)
- RTC: DS3231 for accurate timestamps on logged data
Circuit Design
DC Energy Logger (battery/solar):
INA219 in series with load
Arduino reads V, I, P via I2C every 100ms
Accumulates Wh over time
Displays on OLED: V, I, W, Wh, kWh
Logs to SD card every minute
AC Energy Logger (mains):
ZMPT101B on live wire
ACS712 (30A) on live wire
Arduino samples both at 5kHz (100 samples per 50Hz cycle)
Calculates RMS voltage, RMS current, real power
Accumulates Wh
Arduino Energy Logging Code
#include <Adafruit_INA219.h>
#include <U8g2lib.h>
Adafruit_INA219 ina;
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0);
float totalWh = 0;
unsigned long lastSample = 0;
void setup() {
Serial.begin(9600);
ina.begin();
u8g2.begin();
lastSample = millis();
}
void loop() {
float v = ina.getBusVoltage_V();
float i = ina.getCurrent_mA() / 1000.0;
float p = v * i;
unsigned long now = millis();
float dt_h = (now - lastSample) / 3600000.0;
totalWh += p * dt_h;
lastSample = now;
// Display
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x10_tr);
char buf[32];
sprintf(buf, "V: %.1fV", v); u8g2.drawStr(0, 12, buf);
sprintf(buf, "I: %.2fA", i); u8g2.drawStr(0, 24, buf);
sprintf(buf, "P: %.1fW", p); u8g2.drawStr(0, 36, buf);
sprintf(buf, "E: %.1fWh", totalWh); u8g2.drawStr(0, 48, buf);
sprintf(buf, "kWh: %.3f", totalWh/1000); u8g2.drawStr(0, 60, buf);
u8g2.sendBuffer();
delay(100);
}
Logging to SD Card
Add SD card logging for long-term energy tracking. Log timestamp, voltage, current, power, and cumulative Wh every 60 seconds. Import the CSV into Excel for charts and analysis. Over a month, you will have detailed energy usage data that reveals peak consumption times and inefficient devices.
FAQ
How accurate is a DIY watt-hour meter compared to the electricity board meter?
A well-calibrated INA219-based DC meter achieves 1-2% accuracy. For AC with ZMPT101B+ACS712, expect 3-5% accuracy (limited by sensor linearity and sampling rate). The electricity board’s meter is calibrated to 0.5-1% accuracy. The DIY meter is excellent for relative measurements and trend analysis.
Can I use this to verify my electricity bill?
For rough verification, yes. Monitor your main supply for 24 hours and compare daily kWh with the meter reading. If there is more than 10% discrepancy, investigate — either your DIY meter needs calibration or the electricity meter needs testing.
Add comment