Devices & Components
Arduino Uno Rev3
Cable Assembly, Mini CT 6 Position Receptacle
Current Voltage Multimeter Module
NodeMCU ESP8266 Breakout Board
LED Light Bulb, Frosted GLS
Jumper wires (generic)
Project description
Code
Arduino Code
c_cpp
Upload this code to ESP-32 Device by connecting it with Arduino.
1#include <WiFi.h> 2#include <WiFiClient.h> 3#include <WebServer.h> 4#include <HTTPClient.h> 5#include <PZEM004Tv30.h> 6 7PZEM004Tv30 pzem(Serial2, 16, 17); 8 9const char *ssid = "Huawei Y7"; 10const char *password = "12345678"; 11const char *host = "http://vishwasdiaries.c1.biz"; 12 13 14void setup() { 15 16 // pzem.resetEnergy() 17 18 delay(1000); 19 Serial.begin(115200); 20 WiFi.mode(WIFI_OFF); 21 delay(1000); 22 WiFi.mode(WIFI_STA); 23 WiFi.begin(ssid, password); 24 Serial.println(""); 25 26 Serial.print("Connecting"); 27 28 while (WiFi.status() != WL_CONNECTED) { 29 delay(500); 30 Serial.print("."); 31 } 32 33 34 Serial.println(""); 35 Serial.print("Connected to "); 36 Serial.println(ssid); 37 Serial.print("IP address: "); 38 Serial.println(WiFi.localIP()); //IP address assigned to your ESP 39 40} 41 42//======================================================================= 43// Main Program Loop 44//======================================================================= 45void loop() { 46 47Serial.print("Custom Address:"); 48 Serial.println(pzem.readAddress(), HEX); 49 50 // Read the data from the sensor 51 float voltage = pzem.voltage(); 52 float current = pzem.current(); 53 float power = pzem.power(); 54 float energy = pzem.energy(); 55 float frequency = pzem.frequency(); 56 float pf = pzem.pf(); 57 58 // Check if the data is valid 59 if(isnan(voltage)){ 60 Serial.println("Error reading voltage"); 61 } else if (isnan(current)) { 62 Serial.println("Error reading current"); 63 } else if (isnan(power)) { 64 Serial.println("Error reading power"); 65 } else if (isnan(energy)) { 66 Serial.println("Error reading energy"); 67 } else if (isnan(frequency)) { 68 Serial.println("Error reading frequency"); 69 } else if (isnan(pf)) { 70 Serial.println("Error reading power factor"); 71 } else { 72 73 // Print the values to the Serial console 74 Serial.print("Voltage: "); Serial.print(voltage); Serial.println("V"); 75 Serial.print("Current: "); Serial.print(current); Serial.println("A"); 76 Serial.print("Power: "); Serial.print(power); Serial.println("W"); 77 Serial.print("Energy: "); Serial.print(energy,3); Serial.println("kWh"); 78 Serial.print("Frequency: "); Serial.print(frequency, 1); Serial.println("Hz"); 79 Serial.print("PF: "); Serial.println(pf); 80 81 } 82 HTTPClient http; 83 84 String postData; 85 86String svoltage = String(voltage); 87String scurrent = String(current); 88String spower = String(power); 89String senergy = String(energy,3); 90String sfrequency = String(frequency,1); 91String spf = String(pf); 92 93 postData = "voltage=" +svoltage + "¤t=" + scurrent+ "&power=" + spower+ "&energy=" + senergy+ "&frequency=" + sfrequency+ "&pf=" + spf; 94 95 http.begin("http://vishwasdiaries.c1.biz/test.php"); //Specify request destination 96 http.addHeader("Content-Type", "application/x-www-form-urlencoded"); //Specify content-type header 97 98 int httpCode = http.POST(postData); //Send the request 99 String payload = http.getString(); //Get the response payload 100 101 Serial.println(httpCode); //Print HTTP return code 102 Serial.println(payload); //Print request response payload 103 104 http.end(); //Close connection 105 106 delay(5000); //Post Data at every 5 seconds 107} 108
Downloadable files
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.
Wiring Diagram with NodeMCU

Documentation
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
pzem-004t-100a-wiring-diagram_LhS1ncKEP3.jpg

Comments
Only logged in users can leave comments