Connecting pzem004-t v3 with esp8266 and Blynk

Thanks for the help otherwise the stuffs might ended up in garbage bin.
I can sleep well tonight.

1 Like

Glad it’s finally working.


A post was split to a new topic: Using multiple PZEM sensors

please i did all the steps you mentioned above but i am receiving an error message which says:
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

//here is my code

#include <ArduinoOTA.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <ModbusMaster.h>
#include <ESP8266WiFi.h>
#include "settingsPZEM.h"
#include <SoftwareSerial.h> // ( NODEMCU ESP8266 )
SoftwareSerial pzem(D5,D6); // (RX,TX) connect to TX,RX of PZEM for NodeMCU
//SoftwareSerial pzem(D7,D8); // (RX,TX) connect to TX,RX of PZEM
#include <ModbusMaster.h>
ModbusMaster node;
SimpleTimer timer;
//WiFi data
char ssid[] = "Put your WiFi SSID here"; //WiFi Credential
char pass[] = "Put your WiFi password here"; //WiFi Password
char server[] = "Put your Blynk local server IP address here"; //Blynk local server IP address
int port = 8080; //Blynk local port
#define USE_LOCAL_SERVER //Use local Blynk Server – comment-out if use Blynk hosted cloud service
#define AUTH "put your Blynk App Authorization code here" //PZEM-004v3 Auth code for Blynk Local Server
int timerTask1;
double U_PR, I_PR, P_PR, PPR, PR_F, PR_PF, PR_alarm;
uint8_t result; uint16_t data[6];
void setup(){
Serial.begin(115200); Serial.println("Start serial"); pzem.begin(9600); Serial.println("Start PZEM serial");
node.begin(1, pzem); Serial.println("Start PZEM"); // 1 = ID MODBUS
#if defined(USE_LOCAL_SERVER)
WiFi.begin(ssid, pass);
Blynk.config(AUTH, server, port);
Blynk.begin(AUTH, ssid, pass);
while (Blynk.connect() == false) {}
// timerTask1 = timer.setInterval(1000, updateBlynk);
void updateBlynk() {
Blynk.virtualWrite(vPIN_VOLTAGE, U_PR);
Blynk.virtualWrite(vPIN_CURRENT_USAGE, I_PR);
Blynk.virtualWrite(vPIN_ACTIVE_POWER, P_PR);
Blynk.virtualWrite(vPIN_ACTIVE_ENERGY, PPR);
Blynk.virtualWrite(vPIN_FREQUENCY, PR_F);
Blynk.virtualWrite(vPIN_POWER_FACTOR, PR_PF);
Blynk.virtualWrite(vPIN_OVER_POWER_ALARM, PR_alarm);
void loop(){;
result = node.readInputRegisters(0x0000, 10);
if (result == node.ku8MBSuccess) {
U_PR = (node.getResponseBuffer(0x00)/10.0f);
I_PR = (node.getResponseBuffer(0x01)/1000.000f);
P_PR = (node.getResponseBuffer(0x03)/10.0f);
PPR = (node.getResponseBuffer(0x05)/1000.0f);
PR_F = (node.getResponseBuffer(0x07)/10.0f);
PR_PF = (node.getResponseBuffer(0x08)/100.0f);
PR_alarm = (node.getResponseBuffer(0x09));
Serial.print("U_PR: "); Serial.println(U_PR); // V
Serial.print("I_PR: "); Serial.println(I_PR,3); // A
Serial.print("P_PR: "); Serial.println(P_PR); // W
Serial.print("PPR: "); Serial.println(PPR,3); // kWh
Serial.print("PR_F: "); Serial.println(PR_F); // Hz
Serial.print("PR_PF: "); Serial.println(PR_PF);
Serial.print("PR_alarm: "); Serial.println(PR_alarm,0);

@gemandze please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:


please i need guidance on this code
here is part of the error code

In file included from C:\Users\GEMANDZE DONALD\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkApi.h:37,
                 from C:\Users\GEMANDZE DONALD\Documents\Arduino\libraries\Blynk\src/BlynkApiArduino.h:14,
                 from C:\Users\GEMANDZE DONALD\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp8266.h:24,
                 from C:\Users\GEMANDZE DONALD\Documents\Arduino\sketch_jun11a\sketch_jun11a.ino:2:
C:\Users\GEMANDZE DONALD\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkTimer.h:36:21: error: redefinition of 'class BlynkTimer'
   36 | #define SimpleTimer BlynkTimer
      |                     ^~~~~~~~~~
C:\Users\GEMANDZE DONALD\Documents\Arduino\libraries\SimpleTimer/SimpleTimer.h:10:7: note: in expansion of macro 'SimpleTimer'
   10 | class SimpleTimer {
      |       ^~~~~~~~~~~
C:\Users\GEMANDZE DONALD\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkTimer.h:36:21: note: previous definition of 'class BlynkTimer'
   36 | #define SimpleTimer BlynkTimer
      |                     ^~~~~~~~~~
C:\Users\GEMANDZE DONALD\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkTimer.h:41:7: note: in expansion of macro 'SimpleTimer'
   41 | class SimpleTimer {
      |       ^~~~~~~~~~~
Multiple libraries were found for "SoftwareSerial.h"
 Used: C:\Users\GEMANDZE DONALD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\libraries\SoftwareSerial
 Not used: C:\Users\GEMANDZE DONALD\Documents\Arduino\libraries\EspSoftwareSerial
Multiple libraries were found for "ArduinoOTA.h"
 Used: C:\Users\GEMANDZE DONALD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\libraries\ArduinoOTA
 Not used: C:\Users\GEMANDZE DONALD\Documents\Arduino\libraries\ArduinoOTA
Using library ArduinoOTA at version 1.0 in folder: C:\Users\GEMANDZE DONALD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\libraries\ArduinoOTA 
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\GEMANDZE DONALD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\libraries\ESP8266WiFi 
Using library Blynk at version 1.0.0 in folder: C:\Users\GEMANDZE DONALD\Documents\Arduino\libraries\Blynk 
Using library SimpleTimer at version 1.0.0 in folder: C:\Users\GEMANDZE DONALD\Documents\Arduino\libraries\SimpleTimer 
Using library ModbusMaster at version 2.0.1 in folder: C:\Users\GEMANDZE DONALD\Documents\Arduino\libraries\ModbusMaster 
Using library SoftwareSerial at version 6.12.3 in folder: C:\Users\GEMANDZE DONALD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\libraries\SoftwareSerial 
Using library ESP8266mDNS at version 1.2 in folder: C:\Users\GEMANDZE DONALD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\libraries\ESP8266mDNS 
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

You either need to install the SimpleTimer library, or switch to using BlynkTimer instead.


I already have the Simpletimer library installed but same error still