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 ESP8266module 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.

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.

Step 1: Tests Performed

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.

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.

Step 5: Node-RED Dashboard

Step 6: Arduino IDE Code

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:

empty = Holding Register[0].

Instantaneous voltage = Holding Register[1].

Instant current = Holding Register[2].

Instant power = Holding Register[3].

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.