Meter PZEM-004 + ESP8266 & Platform IoT Cayenne Mydevices

In this opportunity we will integrate our electric consumption or  active power meterPzem-004 of  Peacefair  with the IoT Cayenne mydevices platform using an ESP8266 module, later we will create a dashboard to visualize the 4 available variables such as active power, accumulated electric consumption, voltage and current.

PZEM-004 + ESP8266 12E NodeMCU
PZEM-004 + ESP8266 12E NodeMCU

Cayenne mydevices
Cayenne mydevices

Previous Tutorials Recommended

Introduction IoT Platform Cayenne mydevices & ESP8266

If you want to know more about Cayenne my devices I recommend the following tutorial:

Create account, configuration and basic connection, example esp8266.

Introduction Platform IoT Cayenne mydevices & ESP8266


Electricity consumption meter Peacefair PZEM 004 + ESP8266 & Arduino Nano

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

Features, Connections Arduino and ESP8266 .

Electricity consumption meter Peacefair PZEM 004 + ESP8266 & Arduino Nano

Tests Performed

We will measure the electrical consumption of a resistor to heat water, consume approximately 870 Watts!! and visualize the measurements in a dashboard.

An extension has been manufactured with a multitoma and in one of its wires the CT “Transformer of current” has been placed, although technically the measurement of one of the led lamps is made, and the heating resistance which presents the most significant consumption.

Important Note: do not connect these resistors without being submerged in water, the resistance could be burned instantaneously.

Materials and where to buy them very cheap !!

Other Recommended Equipment



Simple Test Meter PZEM-004 & ESP8266 Platform IoT Cayenne (Complete)


Arduino IDE Code

The routine created in Arduino IDE, esp8266 performs the reading of the meter pzem-004 through the serial port.

Five variables have been defined:

  1. Instantaneous voltage
  2. Instant current.
  3. Instant power.
  4. Accumulated power.
  5. Scan ms, to verify the communication with the esp8266.

For the sending to the Cayenne platform, 8 virtual writing variables have been created, and the data is sent and / or updated every 10 seconds.

Examples:  Cayenne.virtualWrite.

Note: Download links and / or github below.



Dashboards Web Version

After performing the code download to ESP8266, the variables are automatically displayed, they only need to be configured from the widgets.


Dashboard  Cayenne – Android Version

Initially all the configuration of the web version is done, but Cayenne also has an Android app, it simply integrates the same account and displays the dashboards, it is downloadable from its application store, also available for iOs.




Video : Cayenne app  Version Android




Although Cayenne is a good platform, I only found one drawback, it was not possible to send Floating, real or decimal points. The attempt in several ways to send the current, voltage and active and accumulated power were only displayed in integer values, both in the Web version and the Android version.

The drawback in particular is the visualization of values ​​such as the current in mA example 0.8 A = 800mA, you should perform a calculation or multiplezacion according to the figures to be displayed, I hope to have an efficient solution to this dilemma, in the test in particular I had to multiply the current read by 1000, and could only display currents greater than 1A.

In some examples on the network, with cayenne specific widgets it was displayed with decimals, but in my case it did not work, I will continue to consult information in Foros de cayenne, and I will make updates on the subject.

In general there was no major complication, this is just a basic test, in future integrations with Cayenne derived from this project we could perform:

  • Measurements of temperature.
  • Heating resistance control via Rele or PWM AC.
  • Integrations with Wifimanager to facilitate configuration.
  • OTA integrations for remote programming of esp8266.

Note: If you plan to make a complete or permanent connection application with Cayenne Mydevices you must take into account the following regarding terms and conditions.

cayenne is free?

Downloads / Github




Leave a Reply