Advertisement
Intermediate Time: 2–3 weeks Electrical Engineering

Digital Energy Meter with IoT

Design a smart energy meter that measures voltage, current, power, and energy with real-time cloud dashboard.

Energy MeterACS712ESP8266ThingSpeakPower QualityIoT
DifficultyIntermediate
Duration2–3 weeks
Components10 items
Steps10 steps

Introduction

Design a smart energy meter that measures voltage, current, power, and energy with real-time cloud dashboard. This comprehensive guide covers everything from design through implementation, testing, and deployment.

Theory & Background

AC power measurement requires RMS (Root Mean Square) calculations. The Arduino samples the AC waveform at high speed (2000+ samples/cycle), calculates VRMS and IRMS using the Emonlib library, then computes real power (W), apparent power (VA), reactive power (VAR), and power factor (PF = W/VA). True RMS measurement accounts for non-sinusoidal loads like computers and motors.

Advertisement

Components & Requirements

10 components required for this project.

#ComponentPurposeQty
1Arduino Uno R3Main microcontrollerx1
2ACS712 Current Sensor (30A)Non-invasive AC current measurementx1
3ZMPT101B Voltage Sensor ModuleAC mains voltage measurementx1
4ESP8266 NodeMCUWiFi data transmission to cloudx1
5OLED 1.3" Display (I2C)Real-time local readoutx1
6DS3231 RTC ModuleTimestamping energy readingsx1
7SD Card ModuleLocal data loggingx1
810A 250V Calibrated ShuntPrecision current referencex1
95V 2A Power SupplySystem powerx1
10ABS Project EnclosureWeatherproof housingx1

Step-by-Step Implementation

Follow these 10 steps carefully.

1
Understanding AC Power Measurement

AC power measurement requires RMS (Root Mean Square) calculations. The Arduino samples the AC waveform at high speed (2000+ samples/cycle), calculates VRMS and IRMS using the Emonlib library, then computes real power (W), apparent power (VA), reactive power (VAR), and power factor (PF = W/VA). True RMS measurement accounts for non-sinusoidal loads like computers and motors.

2
Calibrating the Voltage Sensor

Connect the ZMPT101B across the mains supply (through a properly fused test lead). Adjust the onboard potentiometer until the output sine wave is within the 0–3.3V range of the Arduino ADC. Measure actual mains voltage with a certified multimeter. In code, apply a voltage calibration factor: VCAL = Actual_Volts / Raw_Volts_Calculated. Typical VCAL for 230V systems is around 234.26.

3
Calibrating the Current Sensor

Connect the ACS712 in series with a known resistive load (e.g., 100W incandescent bulb). The ACS712-30A outputs 66mV/A centered at VCC/2 (2.5V). Measure actual current with a clamp meter. Apply ICAL = Actual_Amps / Calculated_Amps. Zero the sensor by averaging 1000 samples with no load — this compensates for DC offset.

4
Energy Accumulation Logic

Integrate real power over time to calculate energy in kWh: Energy_kWh += (RealPower_W × sample_interval_ms) / (3,600,000). Store cumulative kWh in EEPROM with wear-leveling (rotate across 16 addresses). Read EEPROM on startup to restore total energy after power loss — just like a real utility meter.

5
SD Card Logging

Log timestamp, voltage, current, power, power factor, and cumulative kWh to a CSV file every minute. Create daily files (YYYYMMDD.csv) to limit file size. Use the SD library with the SPI interface. This creates a permanent local record for billing verification and consumption trend analysis over months.

6
Cloud Dashboard Setup (ThingSpeak)

Create a ThingSpeak channel with 6 fields: Voltage, Current, Real Power, Apparent Power, Power Factor, Cumulative kWh. Program ESP8266 to receive data from Arduino via SoftwareSerial and POST to ThingSpeak every 60 seconds using the REST API. Add MATLAB visualizations on ThingSpeak to calculate daily/monthly energy cost at your tariff rate.

7
OLED Display Cycling

Program the OLED to cycle through 3 screens every 5 seconds: Screen 1: Voltage (V) and Current (A), Screen 2: Real Power (W) and Power Factor, Screen 3: Today's kWh and Total kWh. Include a button to manually cycle screens. Display a warning icon when PF < 0.8 (indicating poor power quality from inductive loads).

8
Billing Calculation Feature

Implement a tariff structure: enter your electricity rate per kWh in the code. Calculate daily cost, monthly estimate, and display projected monthly bill. Add slab-based tariff support (e.g., 0–100 units at ₹3.50, 101–200 at ₹5.00) matching your local utility company's billing structure for accurate cost estimation.

9
Over-current Alert System

Set a maximum current threshold (e.g., 20A). When exceeded, immediately publish a MQTT alert and trigger a buzzer. Log the overcurrent event with timestamp to SD card. Optionally integrate a relay to automatically disconnect the load when dangerous current levels are sustained for more than 5 seconds — providing automatic circuit protection.

10
Testing and Validation

Connect a known load (2000W water heater = 8.7A at 230V). Compare meter readings with a reference clamp meter (expect ±1% accuracy). Test power factor measurement with a fan motor (expected PF: 0.6–0.8). Test with LED lights (PF: 0.5–0.9 depending on driver quality). Verify cumulative kWh by running a 1000W load for exactly 1 hour.

Code & Implementation

Core code for energy_meter.ino:

energy_meter.ino C/C++
#include <EmonLib.h> #include <Wire.h> #include <Adafruit_SSD1306.h> #include <SD.h> #include <RTClib.h>  EnergyMonitor emon1; Adafruit_SSD1306 display(128, 64, &Wire, -1); RTC_DS3231 rtc;  #define V_CAL   234.26 #define I_CAL   29.5 #define P_CAL   1.7  float cumulative_kwh = 0; unsigned long lastCalc = 0;  void setup() {   Serial.begin(115200);   emon1.voltage(A0, V_CAL, 1.7);   emon1.current(A1, I_CAL);   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);   rtc.begin();   SD.begin(10);      EEPROM.get(0, cumulative_kwh); }  void loop() {   emon1.calcVI(20, 2000);   float V   = emon1.Vrms;   float I   = emon1.Irms;   float P   = emon1.realPower;   float S   = emon1.apparentPower;   float PF  = emon1.powerFactor;       unsigned long now = millis();   float dt_h = (now - lastCalc) / 3600000.0;   cumulative_kwh += (P * dt_h) / 1000.0;   lastCalc = now;   EEPROM.put(0, cumulative_kwh);       display.clearDisplay();   display.setTextSize(1);   display.setCursor(0, 0);   display.printf("V:%.1fV  I:%.2fA\\n", V, I);   display.printf("P:%.1fW  PF:%.2f\\n", P, PF);   display.printf("kWh: %.3f\\n", cumulative_kwh);   display.display();       Serial.printf("%.1f,%.3f,%.1f,%.1f,%.2f,%.4f\\n", V, I, P, S, PF, cumulative_kwh);   delay(1000); }

Testing & Troubleshooting

Test Digital Energy Meter with IoT by verifying each subsystem individually before full integration.

!
Troubleshooting Tips

Verify power voltages, check ground connections, use serial monitor for debug.

Real-World Applications

*Residential energy monitoring
*Retail electricity billing verification
*Industrial power quality analysis
*Solar system production monitoring
*EV charging station metering
*Laboratory equipment consumption tracking
*Data center power monitoring
*Smart building energy management

Extensions & Next Steps

  • Add harmonic distortion (THD) measurement using FFT
  • Implement prepaid energy metering with RFID top-up
  • Add demand charge monitoring for commercial customers
  • Build a multi-circuit monitor for entire distribution board
  • Integrate with home automation for automatic load shedding

Interactive Playground

Coming Soon

An interactive simulator will be available here — simulate circuits and run code in-browser without hardware.

Frequently Asked Questions

How accurate is this DIY energy meter compared to a utility meter?
With proper calibration, you can achieve ±1–2% accuracy for resistive loads. For reactive loads (motors, switching power supplies), accuracy depends on how well the sensor captures the AC waveform. Commercial utility meters are certified to ±0.5%. Your DIY meter is excellent for monitoring and trend analysis but should not be used for billing disputes.
Can I measure single-phase and three-phase systems?
This design measures single-phase (live + neutral) systems. For three-phase measurement, you need three voltage sensors and three current sensors — one per phase — and sum the real powers. The Emonlib library supports multi-phase measurement with the EmonTx Shield hardware for three-phase systems.
Is it safe to connect sensors to live 230V mains?
The ZMPT101B voltage sensor has an isolation transformer providing galvanic isolation. The ACS712 current sensor is a Hall-effect device that measures the magnetic field around a conductor without direct electrical contact. Both designs are inherently safe when used correctly. However, all AC wiring must be done by a qualified person, with the circuit isolated from mains before any physical connections are made.
How do I measure power factor for different load types?
Resistive loads (heaters, incandescent bulbs) have PF=1.0. Inductive loads (motors, transformers) have lagging PF (0.6–0.9). Capacitive loads (certain electronic equipment) have leading PF. LED lights with poor drivers may have PF as low as 0.5. A power factor below 0.9 means you're drawing more current than necessary, increasing losses in wiring and your electricity bill if billed on kVA.
How long can the SD card log data?
A 2GB SD card can store approximately 2 years of per-minute readings in CSV format (each row ~80 bytes, 60×24×365 = 525,600 rows/year × 80 bytes = 42MB/year). Use a 4GB card for 5+ years of logging. Implement file rotation to delete logs older than 12 months to prevent card overflow in long-term deployments.
Advertisement