Yasiru Tishan
Published © CC BY

Smart Energy Consumption Meter | IoT

This is a smart system for managing the energy consumption of separate devices based on CT Sensor.

AdvancedFull instructions providedOver 6 days2,729
Smart Energy Consumption Meter | IoT

Things used in this project

Hardware components

Current Voltage Multimeter Module
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Cable Assembly, Mini CT 6 Position Receptacle
Cable Assembly, Mini CT 6 Position Receptacle
×1
LED Light Bulb, Frosted GLS
LED Light Bulb, Frosted GLS
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Custom parts and enclosures

pzem-004t-100a-wiring-diagram_LhS1ncKEP3.jpg

Please allow 1-3mm error due to manual measurement. pls make sure you do not mind before you bid
Due to the difference between different monitors, the picture may not reflect the actual color of the item. Thank you!

No Retail Package
Package include:
1 x Multimeter Module (USB adapter is not included)
1 x Split-Core Current Transformer

Schematics

Wiring Diagram with NodeMCU

The above diagram shows how the CT Sensor, Multimeter and Node MCU devices are connected to each other in relation to the entire system. The above clearly shows how the data coming through the CT Sensor is connected to the Multimeter and then to the Node MCU. The multimeter and CT Sensor have several pins. They are interconnected. The CT Sensor has several main pins such as Gnd, Tx, Rx, and 5V. Rx and Tx are used to communicate with the[7] host computer where the object code being compiled is downloaded.
PZEM-004T V3 and ESP-32 Node MCU are communication works on different voltage level theoretically but in practical life 3.3V Node MCU pins have tolerance of 5V. VU pin is USB 5V pin (only works when Node MCU powered through USB)
Although, Node MCU has 11 pins. Of these, two pins are separated by Rx and Tx, leaving nine more. They are called I/O pins. They are named from D0 to D8. As mentioned above, the multimeter is only connected to a few pins on the Node MCU. They are Gnd, D6, D5 and 5V. The Gnd pin on the CT Sensor connected to the Node MCU itself. Also, the pin Tx is connected to the pin D5 of the Node MCU. The pin Rx in CT Sensor is connected to the pin D6. The 5V voltage supplied by the CT Sensor is connected to the 5V of the Node MCU itself.

Code

Arduino Code

C/C++
Upload this code to ESP-32 Device by connecting it with Arduino.
#include <WiFi.h>
#include <WiFiClient.h> 
#include <WebServer.h>
#include <HTTPClient.h>
#include <PZEM004Tv30.h>

PZEM004Tv30 pzem(Serial2, 16, 17);

const char *ssid = "Huawei Y7";
const char *password = "12345678";
const char *host = "http://vishwasdiaries.c1.biz"; 


void setup() {

  // pzem.resetEnergy()
    
  delay(1000);
  Serial.begin(115200);
  WiFi.mode(WIFI_OFF);        
  delay(1000);
  WiFi.mode(WIFI_STA);       
  WiFi.begin(ssid, password);     
  Serial.println("");

  Serial.print("Connecting");

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }


  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());  //IP address assigned to your ESP

}

//=======================================================================
//                    Main Program Loop
//=======================================================================
void loop() {

Serial.print("Custom Address:");
    Serial.println(pzem.readAddress(), HEX);

    // Read the data from the sensor
    float voltage = pzem.voltage();
    float current = pzem.current();
    float power = pzem.power();
    float energy = pzem.energy();
    float frequency = pzem.frequency();
    float pf = pzem.pf();

    // Check if the data is valid
    if(isnan(voltage)){
        Serial.println("Error reading voltage");
    } else if (isnan(current)) {
        Serial.println("Error reading current");
    } else if (isnan(power)) {
        Serial.println("Error reading power");
    } else if (isnan(energy)) {
        Serial.println("Error reading energy");
    } else if (isnan(frequency)) {
        Serial.println("Error reading frequency");
    } else if (isnan(pf)) {
        Serial.println("Error reading power factor");
    } else {

        // Print the values to the Serial console
        Serial.print("Voltage: ");      Serial.print(voltage);      Serial.println("V");
        Serial.print("Current: ");      Serial.print(current);      Serial.println("A");
        Serial.print("Power: ");        Serial.print(power);        Serial.println("W");
        Serial.print("Energy: ");       Serial.print(energy,3);     Serial.println("kWh");
        Serial.print("Frequency: ");    Serial.print(frequency, 1); Serial.println("Hz");
        Serial.print("PF: ");           Serial.println(pf);

    }
  HTTPClient http;   

  String postData;
  
String svoltage = String(voltage);
String scurrent = String(current);
String spower = String(power);
String senergy = String(energy,3);
String sfrequency = String(frequency,1);
String spf = String(pf);

 postData =  "voltage=" +svoltage + "&current=" + scurrent+ "&power=" + spower+ "&energy=" + senergy+ "&frequency=" + sfrequency+ "&pf=" + spf;
  
  http.begin("http://vishwasdiaries.c1.biz/test.php");              //Specify request destination
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");    //Specify content-type header

  int httpCode = http.POST(postData);   //Send the request
  String payload = http.getString();    //Get the response payload

  Serial.println(httpCode);   //Print HTTP return code
  Serial.println(payload);    //Print request response payload

  http.end();  //Close connection
  
  delay(5000);  //Post Data at every 5 seconds
}

Credits

Yasiru Tishan

Yasiru Tishan

2 projects • 5 followers
confident character and goal-oriented team leader and count on interpersonal skills and organizational planning as my critical strengths.

Comments