Asia/Kolkata
Projects

Smart Prepaid Energy Meter

Smart Prepaid Energy Meter – project image by Supratim Mondal
July 29, 2025
Traditional electricity billing suffers from billing errors, delayed payments, and manual reading overheads. This project is a complete IoT-based prepaid smart energy meter that allows consumers to monitor consumption in real time and recharge their balances online. By combining dedicated electrical measurement hardware with an ESP32 microcontroller, a Google Cloud backend, and a Progressive Web App (PWA), the system provides an efficient, end-to-end prepaid energy management solution.
  • Measurement Core: The PZEM-004T module measures RMS voltage, RMS current, active power, frequency, energy, and power factor. It communicates with the ESP32 via UART, utilizing optocouplers for electrical isolation from the high-voltage mains.
  • Microcontroller: An ESP32 manages the local billing calculations, monitors the Wi-Fi connection, updates the local display, and writes safety logs.
  • Power Disconnection: A high-current latching relay is used to connect or disconnect the load. Latching relays only require a short current pulse to switch states, minimizing power consumption.
  • Local Feedback: A 16x2 I2C LCD screen displays the current voltage, power, and active balance. A buzzer provides low-balance warnings.
  • Local State Loop: To handle Wi-Fi drops, all billing and credit deduction calculations run locally on the ESP32. The current balance is updated and saved in the ESP32's non-volatile storage (NVS) every second, ensuring the state survives power cuts.
  • Cloud Backend: Google Cloud Functions and Firestore manage account states, user credentials, and charge histories.
  • Consumer Interface: A React-based Progressive Web App (PWA) provides users with live charts of their energy consumption, transaction logs, and the ability to recharge their meter balance.
  • Decentralized Billing: The billing engine runs on-device, disconnecting the load immediately when credit is exhausted even if the network is down.
  • Secure Control: Relay operations and balance top-ups are validated server-side in Firestore before sending commands to the device.
  • Oversampled Current Sensing: The CT clamp captures high-resolution current data, which is averaged in firmware to reduce line noise.
  • Network Reliability: If the meter relied on cloud API calls to deduct credit, a Wi-Fi drop would allow users to consume unpaid electricity. I resolved this by keeping the billing engine entirely inside the ESP32's firmware, restricting the cloud connection to reporting telemetry and checking for recharges.
  • NVS Wear: Writing to the ESP32's flash memory too frequently (every second) can wear out the flash sector. To solve this, the firmware keeps the active balance in RAM and only writes to the NVS flash when the balance changes by a full unit (e.g., 0.1 Wh) or when a sudden power drop is detected by an interrupt line on the input rails.