Advanced IoT Prepaid Energy Meter: ESP32, PZEM-004T, and a Stunning Web Dashboard

This article details the creation of an advanced prepaid energy meter system, combining the power of an ESP32 microcontroller, a PZEM-004T energy meter module, and a stunning web dashboard for remote monitoring and control. This innovative project offers a comprehensive solution for precise energy monitoring, encompassing voltage, current, power, energy consumption, power factor, and frequency readings. The system's capabilities extend beyond simple data acquisition, incorporating a user-friendly interface accessible via a local TFT LCD display and a secure web dashboard.The project leverages readily available components to provide a cost-effective yet sophisticated solution. Features include remote load control, account management with recharge capabilities, detailed system status monitoring with configurable thresholds, and robust security measures. This guide provides a step-by-step walkthrough of the project, from hardware setup and firmware development to testing and verification, making it accessible to experienced hobbyists and professionals alike. The resulting system offers unparalleled control and insight into energy consumption.

Pros And Cons

PZ EM040 Energy Meter Module
  • Measures voltage, current, power, energy, power factor, and frequency
  • Can be used in a prepaid energy meter system
  • Data can be displayed dynamically on a web server
  • Requires additional components for a complete system (e.g., ESP32, TFT LCD, relay)
  • Mobile dashboard has limited functionality compared to the web dashboard

Read more: AMI Meter Reading Guide: Understanding Your Smart Electricity Meter

Hardware Components and Setup

This project utilizes a robust set of components for precise energy monitoring and remote control. The core is an ESP32 microcontroller, chosen for its Wi-Fi capabilities and processing power. The PZEM-004T energy meter module provides the crucial data acquisition for voltage, current, power, energy consumption, power factor, and frequency. This data is then relayed to a user-friendly interface.

ESP32 microcontroller and PZEM-004T module
ESP32 microcontroller and PZEM-004T module

A 1.8-inch TFT LCD display is integrated for local monitoring, providing a clear visual representation of key energy parameters. User interaction is facilitated by a simple push button for navigating the display's various pages. A relay enables remote control of the connected load, allowing for power switching on and off from the dashboard.

ESP32, PZEM-004T, relay, and TFT LCD connections on a breadboard
ESP32, PZEM-004T, relay, and TFT LCD connections on a breadboard

Web Dashboard and User Interface

The project features a sophisticated web dashboard providing secure access to energy data and control functions. Login credentials ensure secure access, protecting user data and system settings. A clean and intuitive layout displays real-time energy usage parameters and facilitates remote control. The recharge feature integrates directly into the dashboard, streamlining the prepaid energy system.

Prepaid energy meter dashboard showing key parameters
Prepaid energy meter dashboard showing key parameters

Beyond real-time monitoring, the dashboard includes sections for account management, including balance viewing and recharge capabilities. The control section allows for switching loads on and off. Detailed system status monitoring with visual cues and configurable thresholds provides proactive alerts for potential issues or unauthorized access.

Web dashboard login page
Web dashboard login page

Software and Code Overview

The project's functionality is driven by custom firmware running on the ESP32. Libraries are used to interact with the PZEM-004T module, the TFT LCD, and the Wi-Fi network. The code also incorporates web server functionality for the dynamic dashboard. The code integrates seamlessly with the hardware, providing a cohesive and reliable system.

Code editor showing part of the ESP32 firmware
Code editor showing part of the ESP32 firmware

Data management and storage functions are handled using efficient libraries. The web server component of the code uses JavaScript, HTML, and CSS for a responsive and user-friendly interface. Although extensive, the code is well-structured and commented, allowing for further customization and modification.

Section of code showing web server credentials
Section of code showing web server credentials

Testing and Functionality

After uploading the code to the ESP32, the system undergoes testing to ensure all features function as intended. The TFT display showcases boot messages and network connection status. Real-time data is tested by switching loads and observing changes in the displayed parameters. The web dashboard's functionality, including login, recharge, control, and monitoring features, is thoroughly tested.

TFT LCD showing boot messages and IP address
TFT LCD showing boot messages and IP address

The system's accuracy is verified by comparing the displayed energy readings with a known reference. Threshold settings for overvoltage, overcurrent, and theft detection are tested to ensure appropriate alerts are triggered. The stability and responsiveness of both the local and remote interfaces are evaluated.

Web dashboard showing recharge functionality
Web dashboard showing recharge functionality

Conclusion

This advanced prepaid energy meter project showcases a powerful combination of hardware and software, resulting in a robust and versatile solution for energy monitoring and management. The inclusion of an interactive web dashboard and remote control functionality enhances accessibility and control for users. The system's design is comprehensive, addressing various scenarios including fault detection and theft prevention. The use of an ESP32 ensures cost-effectiveness and ease of development.

While the project requires some technical expertise, the detailed instructions and code availability make it accessible to experienced hobbyists and professionals. The well-designed web dashboard provides a professional and user-friendly experience, making it a worthwhile project for anyone seeking to enhance their energy monitoring capabilities.