ESP8266 NodeMCU – Simple energy meter using PZEM004T

In this tutorial we will learn how to use a circuit board with energy measurements capabilities, to acquire the most importante values of an eletrical instalation. The ESP8266, will communicate with a PZEM004T board to gat the values. If you need help on how to start with ESP8266 check the tutorial “ESP8266 NodeMCU – Blinking a LED”.

Parts Required

To build the global setup you must have the following parts:

Note: You do not need to have a NodeMCU board nor an ESP8266 to follow this tutorial. I am using this board because it is very famous and also because, i will post future tutorials using wifi communications. In order to use other boards, you just have to change the pin number.


Figure 1

In many electrical projects, engineer directly deals with measurements with few basic requirements like:

  • High galvanic isolation with;
  • Parameter display;
  • Direct communication with computer;
  • Data acquisition and storage with subsequent viewing or copying to the computer.

PZEM-004T is a board, features all the above requirements and can measure the most important eletrical variables, like:

  • Voltage (V);
  • Corrent (A);
  • Power (W);
  • Power factor (Cos_fi);
  • Reactive Power (VAr);
  • Total Energy consuption.

If you want to know more about the hardware specifications visit manufacturer datasheet.

Last but not least. This module serve all these basic requirements of measurement. You can only use the board to measure the values, but it have some limitations in the current (A) value. If you want to increase max current (A) value, you must add a 33mm diameter current transformer coil (CT), like figure 2. Althougt, it can only measure few A (0-10) without the CT.

Figure 2

Serial Communication

The module is equipped with a TTL serial data communication interface via the serial port, where you can read and set the relevant parameters. Althougt, if you want a device with a USB or RS232 (such as computers) to communicate, then you need to be equipped with different TTL adapter hardware board. Detals can be found in figure 3.

Figure 3

Important notes:

1. This module is suitable for indoor, not outdoor use.
2. the applied load should not exceed the rated power.
3. The wiring can not be wrong.
4. The board must be connected to AC mains because 5V DC only power the TTL logic.


Figure 4

If you use the HI-LINK Power Supply Module, connect the Vcc +5V output to Vin pin, if not you should use another power suplly with the same rates. The RX and TX from PZEM004T goes to GPIO pin 4 (D2) and GPIO pin 5 (D1). The previous GPIO pins, are not serial communications pins. Although, we will use them as such, through some code. Connect the corrent transformer (CT) and the AC live wires in parallel with the load. The wiring in the AC side must be respected as shown in the figure 4.

Danger: Turn off the AC main instalation before connect something. Make sure that everything is unplugged from mains. An error can cause electric shock.


We will use a library from Git-Hub, that communicate with PZEM004T. If you do not know how to instal a library or use the library manager in arduino IDE, you can check Installing Additional Arduino Libraries. Copy the main sketch bellow to your Arduino IDE project and save it.

If you want, you can use three PZEM004T boards and make a 3 phase energy meter. Just have to choose another 4 pins to make the serial communications and also include 2 more software serials in the code.

Note: NodeMCU only have one Serial Port. Because of that, we need to use software serial in order to prevent colision while downloading the code.

3 thoughts on “ESP8266 NodeMCU – Simple energy meter using PZEM004T

  1. Parabéns Ricardo pelo seu trabalho!!
    Você chegou a desenvolver código para poder usar três placas PZEM004T e fazer um medidor de energia trifásico. Conforme você descreveu: “Basta escolher mais 4 pinos para fazer as comunicações seriais e também incluir mais 2 seriais de software no código.”
    Se sim, você pode disponibilizar?
    Desde já o agradeço e parabenizo novamente.
    Antonio Carlos Aguiar Gagno Jr (Vitória-ES-Brasil)
    Whatsapp +55 27 99893 5036

    1. Neste momento não consigo enviar, pois não o tenho disponível no local onde me encontro, mas estará disponível no site em breve.


Leave a Reply

Your email address will not be published. Required fields are marked *