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

In this opportunity we will integrate our active power meter or electric consumption,Pzem-004 – Peacefair with the IoT Node-RED integration platform used in previous tutorials, we will use an ESP8266 module configured as Modbus TCP / IP slave, later we will visualize the measurements in Node- RED Dashboard to visualize the 4 available variables such as active power, accumulated electrical consumption, voltage and current.

PZEM-004 + ESP8266 12E NodeMCU

Previous Tutorials Recommended

Installation Platform Node-Red

In the following tutorial we will indicate how to install Node-RED for linux and in case of other OS we recommend Virtualbox.

Installation Node red Platform

Updating ESP8266 Industrial Modbus TCP IP V2.0

A long time ago I made some tests of ESP8266 as a Modbus TCP/IP slave, the following tutorial can be taken as background information of the current tests.

Update ESP8266 Industrial Modbus TCP IP V2.0

Electricity consumption meter Peacefair PZEM 004 + ESP8266 & Arduino Nano

If you want to know more about Pzem-004  Peacefair , I recommend the following tutorial:

Features, Arduino connections and ESP8266.

Electricity consumption meter Peacefair PZEM 004 + ESP8266 & Arduino Nano

Tests Performed

We will measure the electrical consumption of a resistance to heat water, consume approximately 920 Watts and we will visualize the measurements in a dashboard created in Node-RED Dashboard and the communication implemented Modbus TCP / IP.

Materials and where to buy them very cheap !!

Other Recommended Equipment

Simple Test Meter PZEM-004 & ESP8266 Platform IoT Node-RED Dashboard Modbus TCP/IP



Note: The PZEM-004 meter requires an adaptation to 3.3v communication, more information references below.

 Arduino IDE Code

The routine created in Arduino IDE, ESP8266 performs the reading of the meter PZEM-004  through the serial port, from previous tests with Modbus TCP / IP a routine was created cut for sending and receiving of Holding Registers.

4 variables have been defined in 4 Holding Registers:

  1. empty                       = Holding Register[0].
  2. Instantaneous voltage  = Holding Register[1].
  3. Instant current            = Holding Register[2].
  4. Instant power             = Holding Register[3].
  5. Accumulated power      = Holding Register[4].

Quick solution to shipment of Float in Int

The values of the meter are floating type, the Holding Registers are 16-bit Integers, in this case by practicality simply multiplying by 10 we perform the sending of the value, in next tests we will carry out the shipment in 2 integers of 16 bits.

Note: Download and / or github links below.


The nodes used in this test have been downloaded and installed, simply search the Node-RED “Manage palette”.

In this case, an Array of 5 positions [0,1,2,3,4] is received, the first position in 0 and the rest contains the values of voltage, Current, Power, Accumulated Consumption.

Using some Script nodes the values are separated and is done doing the inverse of Arduino IDE is divided in 10 the values received to convert them from Int to Float in the required cases, technically all this is done for the correct visualization.

Note: Download and / or github links below.

Node-RED Dashboard

Real-time viewing package.

  • View from PC

  • View from Android

The resistance consumes approximately 922 Watts.

Conclusions & Considerations

Well in this opportunity I tried an alternative to the well-known MQTT protocol, this Modbus TCP / IP version worked very well, clearly keep in mind that this application only works at our local network level.

These are still initial tests, since I have not connected multiple slaves, I suppose it will work well since Node-RED is the master, it would depend more on the machine on which Node-RED runs, be it a PC or another platform like Raspberry Pi or Beaglebone Black etc.

In this implementation, the Serial Port of the ESP8266 should not be used since it is used to communicate with the PZEM-004 Electric Consumption Meter.

In pending pending improvements:

  • Updating ESP8266 OTA
  • WifiManager
  • Web server



Leave a Reply