Skip to main content

Revolutionize Power Management with This Scalable IoT Energy Meter System

⚡ IoT-Based Prepaid Energy Meter

⚡ IoT-Based Prepaid Energy Meter with RF Mesh and Firebase Cloud

Managing power consumption efficiently is critical, especially in shared environments like hostels, rental homes, and industrial setups. This project presents a wireless prepaid energy metering system using nRF24L01+, ESP8266, PZEM004T, and Firebase Firestore. The system allows real-time energy monitoring, cloud-based recharge, and automatic cut-off when balance is depleted.


๐Ÿ”ง System Overview

  • Child Node: Arduino Nano + PZEM004T + Relay + nRF24L01+
  • Gateway (Parent Node): ESP8266 (NodeMCU) + nRF24L01+
  • Cloud Backend: Firebase Firestore (NoSQL)

Key Features

  • ⚡ Real-time energy measurement (Voltage, Current, Power, kWh)
  • ๐Ÿ’ฐ Prepaid balance logic with relay cut-off
  • ๐Ÿ“ถ RF communication in scalable tree topology
  • ☁️ Cloud integration with Firebase Firestore
  • ๐Ÿ“ฑ Recharge via Web/App or Firebase Console

๐Ÿ“ถ Multi-Level RF Topology

The system uses an RF mesh where a central ESP8266 Gateway (Parent Node) communicates with multiple child meter nodes.

                 [ Firebase Firestore ]
                           ↑
                   [ ESP8266 Gateway ]
                           ↑
            ┌──────────────┼──────────────┐
            ↓              ↓              ↓
         [Child A1]     [Child B1]     [Child C1]
          + Relay        + Relay        + Relay
          + PZEM         + PZEM         + PZEM

Each child node reports energy usage and balance to the gateway. The gateway then updates the Firebase Firestore document.


๐Ÿ”Œ Communication Protocols

  • UART (Serial): Arduino ↔ PZEM004T (Energy data)
  • SPI: Arduino/ESP8266 ↔ nRF24L01+ (RF transmission)
  • RF (2.4 GHz): nRF24L01+ between nodes
  • HTTP + REST: ESP8266 ↔ Firebase Firestore
  • JSON: For structuring data across all layers
{
  "voltage": 230.5,
  "current": 0.71,
  "power": 165.4,
  "energy": 5.21,
  "balance": 2.34,
  "relay": true
}

๐Ÿ“ก nRF24L01+ Module Variants

1️⃣ Standard nRF24L01+ (PCB Antenna)

  • ๐ŸŸข Compact and budget-friendly
  • ๐Ÿ“ถ Range: ~10–30 meters (indoor)
  • ๐Ÿ”Œ Operates at 3.3V (not 5V tolerant)
  • ๐Ÿ’ก Ideal for short-range and testing

2️⃣ nRF24L01+ PA+LNA (with External Antenna)

  • ๐Ÿ“ก Long-range with Power Amplifier + Low Noise Amplifier
  • ๐Ÿ“ถ Range: Up to 100–1000 meters (LOS)
  • ⚡ Needs stable 3.3V regulator (e.g., AMS1117)
  • ๐Ÿ”ง Recommended for large buildings or campus setups

Tip: Always use a 10ยตF–47ยตF capacitor across VCC-GND to prevent brownouts and instability in PA+LNA modules.


๐Ÿ“„ Firestore Document Example

/energyNodes/childA1
{
  voltage: 229.8,
  current: 0.71,
  power: 162.5,
  energy: 4.32,
  balance: 2.87,
  relay: true,
  lastRecharge: "2021-09-05T14:00:00Z"
}

The ESP8266 gateway updates this document after receiving data from each child node. Recharge values are updated from the app or Firebase Console.


๐Ÿง  Child Node Logic (Arduino + Relay)


if (energyUsed > 0) {
  balance -= energyUsed;
}
digitalWrite(relayPin, balance <= 0 ? LOW : HIGH);  // Relay cutoff

// Send data to gateway
radio.write(&dataPacket, sizeof(dataPacket));

๐ŸŒ ESP8266 Gateway (Firestore Update)


FirebaseJson json;
json.set("voltage", data.voltage);
json.set("energy", data.energy);
json.set("balance", data.balance);
json.set("relay", data.relayStatus);

Firebase.Firestore.patchDocument(&fbdo, projectID, "", 
  "energyNodes/childA1", json.raw(), 
  "voltage,power,energy,balance,relay");

๐Ÿ’ฐ Recharge Process

You can recharge the balance using a web/app interface or directly from the Firebase Console by updating:


/energyNodes/childA1/balance = current_balance + recharge_amount

The updated balance is pulled and applied during the next communication cycle by the gateway and passed to the child node.


๐Ÿ“ˆ Applications

  • ๐Ÿ  Prepaid metering in hostels and PGs
  • ๐Ÿข Machine-level energy management in factories
  • ๐Ÿก Smart sub-metering in apartments
  • ๐ŸŒ Rural and off-grid electrification
  • ๐Ÿ›  Multi-tenant commercial buildings

๐Ÿš€ Optional Future Upgrades

  • ๐Ÿ”” Low-balance notifications to mobile app
  • ๐Ÿ“Š Daily energy logs with timestamps in Firestore
  • ๐Ÿ”„ OTA firmware updates via Wi-Fi
  • ๐Ÿ”— UPI-based recharge with transaction history
  • ๐Ÿ“ถ Replace nRF24L01+ with LoRa for long-range use

  • PZEM004T TX ↔ Arduino RX
  • Relay IN ↔ Digital Output Pin
  • nRF24L01+ ↔ SPI (MOSI, MISO, SCK, CSN, CE)
  • Use AMS1117 or HT7333 to power nRF module

๐Ÿ›ก️ Shadow Master Node (Failover ESP8266)

To improve reliability, especially in large-scale or critical deployments, a Shadow Master Node (another ESP8266) can be used. This node listens for heartbeat signals from the main ESP8266 gateway. If the heartbeat is lost for more than 15 seconds, it automatically takes over gateway responsibilities (polling meters and sending data to Firebase).

⚙️ Features

  • ๐Ÿ” Auto switch-over from main gateway
  • ⏱️ Heartbeat detection every 5 seconds
  • ๐Ÿ“ค Uploads data to Firebase during failover
  • ๐Ÿ”™ Reverts to passive when primary gateway is back

๐Ÿง  Failover Logic


// If heartbeat is received:
lastHeartbeat = millis();

// If heartbeat timeout (15 seconds):
if (millis() - lastHeartbeat > 15000) {
  isMaster = true; // Shadow takes over as master
}

๐Ÿ“ก RF Communication

  • Master sends "HEARTBEAT" over RF every 5 seconds
  • Shadow listens using nRF24L01+ on pipe "HBART"
  • If missed for 15s, Shadow becomes master
  • On receiving heartbeat again, it returns to standby

๐Ÿงฉ Deployment Tip

Place the Shadow Node in a different power line or area to ensure redundancy in case of hardware/power failure on the main ESP8266.


๐Ÿ“ฅ Want the Full Project?

Comment below or contact me to get:

  • ✅ Full Arduino + ESP8266 code (Node + Gateway + Shadow)
  • ✅ Firestore database rules and JSON templates

๐Ÿงฉ Tip:

Use multiple child nodes with unique addresses. The ESP8266 gateway can handle 10+ meters efficiently using RF polling and Firestore batching.

Let’s make energy metering smarter, scalable, and cloud-connected!

Comments

Popular posts from this blog

Voice Controlled Home Automation and Home Security System

 Abstract— In this paper, Google assistant has been used to control the light, fan, and water pump by saying Ok Google, turn the light ON or OFF. Then IFTTT interprets the message and can send it to Blynk’s dashboard as an understandable command to the created feed. The proposed prototype uses to control home appliances anytime from anywhere in the world and efficiently utilize power by controlling appliances properly by an Android OS smartphone. Blynk app has been used to analyze data about temperature, humidity, fire, and water level to control home appliances. The voice commands for Google assistant have been added through the IFTTT website linked with Blynk. Keywords— NodeMCU, Blynk app, Google Assistant, IFTTT website, DHT11 Sensor, PIR Sensor, Ultrasonic Sensor, Flame Sensor, and Relay Module I. INTRODUCTION With the advancement of technology, the need for efficient controlling is more as it optimizes performance and saves unnecessary wastage of power. Home automation allows ...

AUTOMATIC ROOM LIGHTING SYSTEM

๐Ÿ”† Automatic Room Lighting System ๐Ÿ”† Automatic Room Lighting System Date: October 30, 2021 Purpose: Energy conservation through automation using IR sensors and a microcontroller. ๐Ÿ”ฐ Introduction Electricity is an indispensable part of modern life. However, with rising energy demands and depleting non-renewable resources, energy conservation has become a necessity . One major area where energy is often wasted is lighting—many people forget to switch off lights when leaving a room. To address this, we’ve designed an Automatic Room Lighting System , which uses IR sensors and a microcontroller (ATmega32) to automatically switch lights ON or OFF based on room occupancy. This system not only helps reduce electricity bills but also promotes responsible energy usage. ๐Ÿง  Working Principle Entry: Sensor 1 → Sensor 2 → Light ON + Counter++ Exit: Sensor 2 → Sensor 1 → Counter-- → Light OFF if Count = 0 This project is based on a bi-directional human detectio...