DIY IoT Smart Energy Meter With ESP32, LoRa - Web Monitoring
by Rau7han in Circuits > Wireless
18347 Views, 82 Favorites, 0 Comments
DIY IoT Smart Energy Meter With ESP32, LoRa - Web Monitoring
In this project, we build a long-range IoT energy monitoring system using ESP32, LoRa, and a custom web dashboard. It measures voltage, current, power, and energy in real time and allows remote control of loads.
Whether you want to monitor a remote farm, a large hostel, or just learn how wireless energy monitoring works, this project is perfect for you.
What You Will Learn
By completing this project, you'll understand:
- LoRa Communication: How to send data wirelessly over kilometers without Wi-Fi.
- Energy Monitoring: How to safely measure Voltage, Current, Power, and Frequency using the PZEM004T sensor.
- Web Servers on ESP32: How to host a website directly on a microcontroller.
- Real-Time Data: How to sync time using NTP servers for accurate billing.
- Remote Control: How to switch appliances ON/OFF remotely via the web dashboard.
Safety First!
This project involves measuring mains electricity.
- Always disconnect mains power before wiring the PZEM module
- The PZEM004T module is designed to be safer than direct connections, but it still interfaces with high voltage.
- Never touch exposed wires while the system is powered.
- Use a proper enclosure (plastic box) to hide all connections.
- If you are unsure about working with mains electricity, ask for help from an adult or a qualified electrician.
- For testing, you can power the ESP32 via USB and simulate data before connecting to high voltage.
This system also supports remote relay control and automatic billing calculation, making it useful for real-world monitoring setups
Supplies
Required Material
- ESP32 Development Board ×2 (Transmitter + Receiver) (Amazon.com)
- LoRa SX1278 Module ×2 (Amazon.com)
- PZEM004T v3.0 Energy Meter Module ×1 (Amazon.com)
- ST7735 TFT Display ×1 (Amazon.com)
- SSD1306 OLED Display ×1 (Amazon.com)
- Relay Module ×1 (Amazon.com)
- Push Button ×1 (Amazon.com)
- Jumper Wires (Amazon.com)
- Breadboard (optional)
- 5V Power Supply (Amazon.com)
Tools
- Soldering Iron and Solder (Amazon.com)
- 3D Printer (Amazon.com)
- Screwdriver Set (Amazon.com)
- Computer with Arduino IDE installed
- USB Cable (for programming ESP32)
For the box, you will need:
- The files attached to this step
- 3D printer
- Filament: PLA recommended
- Slicing software
Sponsored by NextPCB
This project was successfully completed with the support of NextPCB, a reliable multilayer PCB manufacturer. With over 15 years of experience in PCB fabrication and assembly, NextPCB offers high-quality and dependable PCB solutions for makers and professionals worldwide.
You can order high-quality PCBs starting at $1.9, and multilayer PCBs starting at $6.9:
https://www.nextpcb.com/pcb-quote
Get free PCB assembly for up to 5 boards:
https://www.nextpcb.com/pcb-assembly-quote
With comprehensive Design for Manufacture (DFM) analysis features, HQDFM is a free, sophisticated online PCB Gerber file viewer.
How It Works?
This project consists of two ESP32-based units: a transmitter (meter unit) and a receiver (monitoring unit). The transmitter measures electrical parameters using a PZEM004T energy meter module and sends the data wirelessly using LoRa. The receiver collects this data, displays it locally, and publishes it to a web dashboard for monitoring and control.
Before we start wiring, let's understand the flow. This system has two main parts:
- The Transmitter (Meter Unit):
- It reads electricity data using the PZEM004T.
- It shows the data on a TFT Screen.
- It sends the data wirelessly using LoRa.
- The Receiver (Monitoring Unit):
- It catches the LoRa signal.
- It shows connection status on an OLED Screen.
- It hosts a Web Dashboard so you can check data from your phone or laptop.
Data Flow:
PZEM Sensor → ESP32 Transmitter → LoRa Radio → ESP32 Receiver → Web Dashboard
Wiring the Transmitter
Let's build the unit that measures the energy. We need to connect the ESP32 to the Sensor, LoRa module, and Display.
🔹 PZEM004T Connections (ESP32)
• PZEM TX → ESP32 GPIO16
• PZEM RX → ESP32 GPIO17
This module measures voltage, current, power, frequency, and energy consumption.
🔹 LoRa Module Connections
• NSS → GPIO15
• RST → GPIO14
• DIO0 → GPIO26
• MOSI → GPIO23
• MISO → GPIO19
• SCK → GPIO18
These pins are used for SPI communication.
🔹 TFT Display Connections (ST7735)
• CS → GPIO5
• DC → GPIO21
• RST → GPIO22
This display shows live readings and system status.
🔹 Button and Relay
• Button → GPIO4 (used for page switch + reset)
• Relay → GPIO2 (used for load control)
Wiring the Receiver
Now, let's build the unit that receives the data and shows you the website.
Follow the wiring carefully based on the pin configuration used in the code.
🔹 LoRa Module Connections (ESP32 Receiver)
• NSS → GPIO15
• RST → GPIO14
• DIO0 → GPIO13
• MOSI → GPIO10
• MISO → GPIO11
• SCK → GPIO12
These pins handle SPI communication for LoRa data reception.
🔹 OLED Display Connections (SSD1306)
• SDA → GPIO17
• SCL → GPIO18
The OLED shows system status such as IP address, signal strength, and connection status.
🔹 Power Notes
Make sure:
• Both ESP32 and LoRa module share common GND
• Use stable 5V supply for reliable operation
Do NOT power the circuit while wiring.
Assemble the Setup
Assemble the transmitter and receiver using the wiring diagram, connecting each module step-by-step and testing individually before final assembly.
In both units, the ESP32 works as the main controller for sensing, communication, and control. The PZEM004T measures voltage, current, power, and energy, while the LoRa modules handle long-range data transfer.
The transmitter shows live readings on the TFT display, and the receiver shows status (IP, signal strength) on the OLED and hosts the web dashboard for monitoring and relay control.
Soldering the Circuit Onto Perfboard
Solder all modules carefully onto the perfboard one at a time. Working step-by-step helps avoid mistakes and makes troubleshooting easier.
Start with the smaller and lower-profile components first, such as:
- PZEM connection headers
- Button
- Small connectors or pin headers
Next, solder the ESP32 headers and supporting components. After that, solder the LoRa module connections carefully according to the wiring layout.
Make sure:
- All pins are aligned correctly before soldering
- Modules sit flat on the board
- No pins are shorted together
Incorrect alignment can damage components or prevent the system from working properly.
Continuity Testing
After soldering each section, check connections using a multimeter in continuity mode.
Steps:
- Place one probe on the component pin
- Place the other probe on the corresponding connection point
If you hear a beep or see near-zero resistance, the connection is correct.
This step helps identify loose joints, broken traces, or accidental shorts before powering the circuit.
Transmitter Code
You don't need to be a coding expert, but understanding what the code does helps with troubleshooting. The code is divided into logical sections:
WiFi & Time Sync:
The ESP32 tries to connect to WiFi to get the exact time from an NTP server. This ensures your energy bills are timestamped correctly. If WiFi fails, the meter still works, but the clock won't sync.
Sensor Reading:
It constantly asks the PZEM004T for Voltage, Current, Power, and Frequency. It includes "noise filtering" to ignore sudden spikes that aren't real.
Energy Tracking:
It calculates how much energy you've used today, this month, and total lifetime. This data is saved in the ESP32's memory so you don't lose it if power goes out.
Display System:
- Page 1: Shows live Voltage/Current.
- Page 2: Shows total consumption and time.
- Button: Short press changes pages; Long press resets consumption.
LoRa Transmission:
- Every few seconds, it packs all this data into a message and shoots it over the air to the receiver.
- Download the GitHub repo: loRa-smart-energy-meter
- Open .ino in Arduino IDE.
- Connect your Board.
- Install Library.
- Choose the correct COM port
- Click Upload.
Downloads
Receiver Code
The receiver code is the "brain" of the monitoring system.
- LoRa :
- It listens constantly for packets from the transmitter. It checks if the data is valid (not corrupted) before using it.
- OLED Status Screen:
- Shows you the IP address (so you know where to go in your browser), signal strength (RSSI), and connection status.
- Web Dashboard:
- The ESP32 acts as a web server. You can log in to see:
- Live Readings: Current voltage and power.
- History: Daily and monthly usage charts.
- Billing: Calculates cost based on kWh usage.
- Control: A button to turn the Relay ON/OFF remotely.
- Remote Relay Control:
- When you click "Turn Off" on the website, the receiver sends a LoRa command back to the transmitter to switch the relay.
Downloads
Software and Libraries Setup
To upload code to the ESP32, you need the Arduino IDE with ESP32 board support and the required libraries installed.
🔹 Install ESP32 Board Support
- Connect your ESP32 to the computer using a USB cable.
- Open Device Manager and confirm it appears as CP210x USB to UART (COMx).
Now install ESP32 support:
• Open Arduino IDE → File → Preferences
• In Additional Boards Manager URLs, add:
https://dl.espressif.com/dl/package_esp32_index.json
• Go to Tools → Board → Boards Manager
• Search ESP32 by Espressif Systems and install
After installation:
Go to Tools → Board → ESP32 Dev Module
🔹 Install Required Libraries
Before uploading the code, install these libraries:
• LoRa
• Adafruit GFX
• Adafruit SSD1306
• Adafruit ST7735
• PZEM004Tv30
Install from:
Tools → Manage Libraries
🔹 Upload and Test
• Open transmitter or receiver code
• Select correct board and COM port
• Click Upload
After upload:
Transmitter → TFT shows readings
Receiver → OLED shows IP address
Open browser → enter IP → login and test dashboard + relay control.
Print and Assemble Enclosure
Print the enclosure and assemble both the transmitter and receiver units inside the case. This keeps the setup compact, safe, and more professional.
🔹 Step 1 — Print the Enclosure
- Download the enclosure STL file attached to this step.
- Open your slicer software (Cura, Bambu Studio, PrusaSlicer, etc.).
- Import the STL file and select your printer profile.
Recommended settings:
• Material: PLA
• Layer height: 0.2 mm
• Infill: 20–40%
• Supports: Not required
- Slice and export the file.
- Start printing and wait until complete.
The enclosure includes cutouts for the display, antenna, and cable routing as shown in the images.
🔹 Step 2 — Install the Antenna
- Insert the SMA antenna connector into the side hole of the case.
- Tighten it securely using the nut.
- Attach the antenna to the connector from outside.
This ensures stable LoRa signal performance.
🔹 Step 3 — Fit the Circuit Boards
Transmitter Unit
- Place the perfboard assembly inside the enclosure carefully.
- Align the TFT display with the front opening.
- Ensure the relay and PZEM module sit properly without pressure ( i use double sided tape for this).
Secure the board using:
• Hot glue (recommended)
or
• Double-sided tape (temporary setup)
Receiver Unit
- Place the receiver perfboard into the enclosure.
- Align the OLED screen properly with the opening.
- Route the antenna wire neatly inside the box.
🔹 Step 4 — Cable Management
• Arrange wires neatly to avoid pressure points
• Keep mains wiring separated from signal wiring
• Ensure nothing touches sharp edges
🔹 Step 5 — Final Check
Before closing:
• Confirm displays align properly
• Check antenna connection
• Ensure no loose wires
I did not design a lid for this enclosure since I am still learning 3D printing. You can redesign or customize the lid according to your setup.
Testing, Demo & Verification
we will test the complete system to ensure stable communication, accurate readings, and reliable dashboard performance. Perform testing in stages to verify each function properly.
Step 1 — Initial Power Test
Power both transmitter and receiver units.
Check:
• Transmitter TFT turns ON and shows readings
• Receiver OLED shows WiFi IP address
• No overheating or unusual behavior
If everything looks stable, continue.
🔹 Step 2 — LoRa Communication Test
Keep both units near each other first.
Check:
• Receiver starts showing live data
• OLED displays RSSI value
RSSI closer to 0 (example −50) = stronger signal than −100.
🔹 Step 3 — Dashboard Test
- Connect phone/laptop to same WiFi network.
- Open browser and enter receiver IP.
Test:
• Live values update smoothly
• Charts load properly
• Relay ON/OFF works instantly
Web Dashboard Testing & Demo
In this step, we test both Admin and User interfaces of the Energy Meter web dashboard. This confirms real-time monitoring, billing calculation, relay control, and system stability.
Login Test (Admin + User)
Open a browser and enter the IP address shown on the OLED screen.
Login credentials:
• Admin → admin / admin123
• User → user1 / pass123
After login, the dashboard loads automatically depending on the role.
Admin Dashboard Overview
The admin dashboard provides full system monitoring and control:
• Total connected devices
• Monthly consumption and billing
• Device connection status
• Monthly usage charts
Data updates automatically without refreshing the page.
🔹 Device Detail Monitoring
Open the device detail page to verify live readings.
Check:
• Voltage updates continuously
• Current changes with load
• Power and frequency remain stable
• Consumption values calculate correctly
This confirms accurate PZEM readings and stable LoRa transfer.
🔹 Relay Control Testing
Test remote switching:
• Click Cut Power / Restore Power
• Relay responds instantly
• Load turns ON/OFF properly
This confirms bidirectional LoRa communication.
🔹 Billing and Unit Price Configuration
Test billing features:
• Change unit price
• Save settings
• Monthly bill updates automatically
🔹 User Dashboard Testing
The user dashboard allows simple monitoring:
• Live voltage/current/power
• Monthly usage
• Billing status
• Weekly trend chart
Users cannot control relay or settings.
🔹 Settings Page Verification
Check system status:
• Device ID
• Firmware version
• IP address
• LoRa RSSI
• Live connection status
Field Testing
Now the system is ready for real field testing. In my setup, I used a Hi-Link HLK-PM01 AC-to-5V module, so an external 5V adapter was not needed. The AC mains was first connected to the Hi-Link module, which safely converted it into regulated 5V to power the ESP32 transmitter.
After that, the AC line was connected to the PZEM004T exactly according to the wiring diagram. The phase wire was passed through the PZEM input/output terminals, while the neutral wire was connected directly to the load.
Once powered ON, the TFT immediately started showing live readings, and the receiver OLED displayed the IP address along with connection status. Opening the web dashboard confirmed that voltage, current, and power values were updating smoothly in real time.
For testing, I used a simple 10W LED bulb as the load and operated the system mainly during one night. Because the load was small and used for a short time, the energy consumption values shown in the dashboard are low. However, the goal of this test was to verify system stability, communication, and accuracy rather than long-term measurement.
During testing, the transmitter measured voltage, current, power, and frequency correctly. The receiver displayed all readings accurately with smooth updates. Even with a small load, the readings remained stable and consistent.
Overall, the system performed well and delivered accurate results for the test conditions. Although this test used only a 10W bulb, the setup is fully capable of handling larger loads and long-term monitoring in real applications.
This Instructable explains the full build process, from the initial breadboard prototype to the final permanent perfboard version.