IoT Energy Meter nodemcu

 

IoT Energy Meter 

Components:

  • ESP8266

  • PZEM-004T Energy Meter Module

Circuit:



  • Connect the PZEM-004T to the ESP8266 as follows:

    • PZEM-004T:

      • TX → RX of ESP8266

      • RX → TX of ESP8266

      • VCC → 5V

      • GND → GND

Code:

cpp
#include <ESP8266WiFi.h> #include <SoftwareSerial.h> #include <PZEM004Tv30.h> const char *ssid = "your-SSID"; // Replace with your WiFi SSID const char *password = "your-PASSWORD"; // Replace with your WiFi Password WiFiServer server(80); PZEM004Tv30 pzem(Serial); // Software serial or hardware serial SoftwareSerial swSerial(D6, D7); // RX, TX for PZEM-004T void setup() { Serial.begin(115200); swSerial.begin(9600); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); } Serial.println("Connected to WiFi!"); server.begin(); } void loop() { WiFiClient client = server.available(); if (client) { String response = "Energy Consumption Data:<br>"; response += "Voltage: " + String(pzem.readVoltage(), 2) + " V<br>"; response += "Current: " + String(pzem.readCurrent(), 2) + " A<br>"; response += "Power: " + String(pzem.readPower(), 2) + " W<br>"; response += "Energy: " + String(pzem.readEnergy(), 2) + " Wh<br>"; client.print(response); delay(1000); } }

Post a Comment

0 Comments