Electricity consumption meter Peacefair PZEM 004 + ESP8266 & Arduino Nano

For some time I wanted to buy a single-phase electricity consumption meter, a few months ago I got Peacefair Reference PZEM-004 meter, its price seemed affordable, it has the advantages of being a non-invasive meter in the electrical circuit and has a communication protocol to request data such as Active Instantaneous Power “kW”, Voltage “V”, Amperage “A” and Active Power Accumulated “kWh”.

Warning: Caution is recommended since this project involves electrical risk or electrocucion since 110 VAC -120 VAC connected equipment is used, basic knowledge is required, please be previously documented in this regard.

There are 2 versions

This meter is very popular in electrical consumption measurement projects and there are 2 versions depending on the application required.

PZEM-004T

PZEM-004

Comparing both versions, technically identical, the difference lies in the visualization that one has and the other does not.





 

Meter Connections

Tutorial

We will perform some tests on the PZEM-004 Meter and integrate it with 2 platforms or plates already used before the ESP8266 12E module and an Arduino Nano.

Summary Characteristics

This meter PZEM-004 allows to visualize the 4 variables with 4 display 7 segments of 4 figures each, has a complete core current transformer, which fulfills the function of sensing the current, is said to be a non-invasive meter by that does not require modifying or intervening the measurement circuit. The voltage measurement points are the same for which the meter is powered, it has a 5V UART TTL interface and a protocol to request the data mentioned above.

Front view

  • Front push button. allows you to reset the accumulated kWh.

Back view

It has space for a buzzer, in some it has it in my case, fortunately because it constantly sounds when communicating, its function is alarm by maximum limit of active power.

The main integrated is the SD3004 that is under the green label performs technically everything, Measurements, conversions, calculations, control of the 7 segments and serial communication.

Datasheet : SDIC  SD3004

On the left above there is another built-in I²C EEPROM external memory that stores the kWh, in case of turning off the meter do not restart the accumulated.

Above the communication port “TTL PORT” has 2 optocouplers for the isolation of serial communication.

In the lower part there is a transformer some diodes, capacitors and a regulator is synomino of a source, for the SD3004, IMPORTANT this source is not isolated, do not connect other devices of this, possibly generate a short circuit.





 

Library PZEM004T for Arduino IDE

Given the popularity of these meters, there are some libraries for Arduino IDE to facilitate communication and specifically the request for data, I consider the most popular version created by olehs, thank you for your contribution.

Github : library  PZEM004T.h

Modification TTL UART from 5v to 3.3v

The UART interface of the meter is 5v. In the case of connecting the meter to an Arduino board, no problem will work correctly, in case of connecting with an ESP8266 module at 3.3v it will not work, since the optocouplers will not be activated with 3.3v, in that case a conditioning should be carried out of signal the simplest method that I have seen in the internet, to modify the voltage of one of the optocouplers with a resistance of 1kOhm, is the simplest and most economical way if a TTL converter of 5 to 3.3v is not available.

Note: Some forums indicate that caution should be used when connecting the TTL to a PC, I confess I was afraid to connect this meter to my pc, thinking about the isolation of the meter but in my case there were no problems.

  • Meter without modification, factory

  • Meter with modified resistance 1k.

 





 

Current transformer

The meter PZEM 004,  brings a current transformer, apparently full-core, this transformer measures current without interrupting the circuit, being very practical, although commercially the current transformers or “CT” has a relationship that indicates its range of measure, this transformer does not specify its characteristics, in some forums speculate and has made some tests.

This transformer to be full core in some cases could hinder the assembly at the points of measurement, in the market there are a variety of split core transformers, I will buy some and try the variations, but attention is not any transformer to work since the any variation will generate errors in the final measurement.

Test Arduino Nano 

Of all the arduino, plates, the Nano version is my favorite since it is practical, small and has FTDI / usb included. With the modification we made to the UART ttl, we can use the arduino to 3.3v, making a direct connection.

In this case we use an Arduino Nano  board, which only has a single serial port, the PZEM004T.h library has the ability to create another serial port with the SoftwareSerial.h library, we will use the D10 (RX) and D11 (TX) pins ) As communication port with the meter.

The SoftwareSerial library used is the version for ESP8266, not the original SoftwareSerial version for arduino, since the original version for arduino uses AVR libraries not available for esp8266, full downloads in bottom part.

Note: Using SoftwareSerial to 9600, at higher speeds, optimal transmission is not guaranteed.

  • Arduino IDE Code

Note: Complete Download Down.

  • Serial Terminal

  • Connections

 





 

Test ESP8266 12E

For this test we will use an ESP8266 12e NodeMCU,

Since it is only a revision, we will perform a basic test, taking into account that the PZEM004T.h library with the SoftwareSerial.h library that allows to configure pins in serial ports to 9600 bauds.

There have been 3 tests of connection and communication with the Peacefair meter, sadly the first 2 tests did not work correctly, the communication was intermittent, the last connection worked correctly, then the 3 connections available.

Connections test 1:

In this case, SoftwareSerial.h uses the GPIO 13 (Rx) and GPIO 15 (Tx) pins:

 

Conclusion: When performing the test, I communicated intermittently, although in some moments I only requested the Voltage, I discarded this connection, I will continue testing.

Note: GPIO15 must be down when restarting ESP8266,  Q1 prevents it from rising and ESP does not start in Firmware mode.

 

Connections test 2:

In this case, SoftwareSerial.h uses the GPIO 4 (Rx) and GPIO 5 (Tx) pins:

Conclusion: the response was similar to the previous test, communicated intermittently returning in some cases Voltage and watts / hour, discarded this connection, I will continue testing.

 

Test connections 3: Version used

In this case, SoftwareSerial.h uses the GPIO 3 (Rx) and GPIO 1 (Tx) Serial pins, or programming and debug port:

Conclusion: As a final test, the direct connection to the serial programming port of the ESP8266 module is made, in this case if the communication is correctly made with the meter, returning the 4 measurement values, this connection has been chosen for the test.

Important: The only practical disadvantage is that since the Serial port is used for communication with the Peacefair meter, the port Serial.begin (9600); must not be used and / or enabled since it would interfere with the communication, other methods of debugging should be looked for without using the serial, for that case I have created a routine with a web server.

Arduino IDE in my case downloaded without problems, the code without requiring disconnecting the communication with the peacefair meter, since the meter only transmits on request, also given to the optocouplers.

Note: Download Arduino IDE Complete code below.

 





 

Materials and Where to Buy Cheap!!!

Other Recommended Equipment

 

 

Test Power Meter PZEM 004 Peacefair + Arduino & ESP8266

  • Complete test

 

Comparison Measurements: Peacefair PZEM 004 Meter VS Chint Meter DDS666 + ESP8266





 

Recommended Tutorials

Meter PZEM-004 + ESP8266 & Platform IoT Cayenne Mydevices

Meter PZEM-004 + ESP8266 & Platform IoT Blynk App

Meter PZEM-004 + ESP8266 & Platform IoT Node-RED & Modbus TCP/IP





 

 

Conclusions

Initially, a lot of caution should be taken since this project involves electrical risk or electrocution since 110VAC -120 VAC is used, although some do not consider it high voltage, this does not minimize the danger, it is recommended to have basic knowledge or documentation, never make connections When hot, always de-energize the power circuits.

The PZEM 004 meter, is very practical, very basic and its low price meets good performance, I do not recommend it for industrial applications taking into account the environment, its point of measurement of VAC is the same point of feeding, allowing measurements between 80-260VAC.

Current measurement from 0 to 100A, well I’m not sure that this transformer supports 100A, but I’ll continue investigating.

Warning: Do not take either 5v or 3.3v directly from the source of the meter, if you feed your modules add an extra source, to avoid short circuits.

  • Do not make modifications to the measuring circuit of the meter if you do not have enough knowledge.

Arduino

In the case of testing with Arduino there was no problem, initially I was very hesitant to connect the meter to Arduino and specifically to my PC, taking into account the isolation of GND, but in my case there was no problem after studying in detail the meter, but be careful.

ESP8266

In the case of module ESP8266, there were 2 drawbacks:

1. Serial communication voltage level 5v to 3.3v, it was required to modify the consumption meter or buy a TTL converter, a test was performed adding a resistance of 1kOhm.

2. Connection and communication, 3 connections were made available in the network, at first sight they should work but, they worked intermittently, requesting only “Voltage”, I will validate if the resistance is the cause of the intermittence although with the port serial0 of the without any complication.

In the case of ESP8266, since the programming port is busy, an attempt will be made to implement OTA applications.

In next tutorials we will integrate this meter to previously tested IoT platforms such as Emoncms, Node-RED, Cayenne mydevices, blynk, AdafruitIO, Ubidots, ThingSpeak, among others.

If you have suggestions comments or have done tests with this type of meters please comment your experience

Downloads

References and Acknowledgments

 





 

Leave a Reply