Can't communicate with PZEM-004 module, how can I test if it works?

Hello everyone,

this week I got the PZEM-004 module and I wanted to test it, as I want to use it with an ESP8266 i connected directly to that board, but it always returned -1 for each value (v, w, wh) after trying to get some help on github but couldn't make it work.

To remove one of the possible problems (ESP runs on 3.3v, PZEM is 5v) I tried to flash an arduino pro micro that runs on 5v, and connect this to the PZEM but I get 0v, even if now I connected the AC cable (nothing through the coil, but it hould report the tension and 0w as the power, but I get 0v)

I used the code I found in this forum and connected everything togheter with no luck. I alo tried to swap the RX/TX wires in case I mounted them incorrectly

Is there a way to somehow test the PZEM module ?

Here is a video with my setup

Is my module dead? Or I do something wrong ?

Any help is welcome.

How is everything wired?

What sketch are you using?

What library are you using, if any?

  1. In the picture bellow you can see how I connected the Arduino with the PZEM module, pin 2 of arduino to pin 3 of PZEM, pin 3 of arduino to pin 2 of PZEM. 5v from VCC of arduino to pin 1 of PZEM. AC voltage is connected on the other connector, but through the coil I don;t have any wire, it should display the voltage and 0w for power

  2. The sketch I used in this Arduino Pro Micro was copied from this forum, I just modified it to actually show the actual value received from PZEM instead of 0v, so it shows -1 for each option, exactly like the other code shown when I tested with the ESP8266.

#include <SoftwareSerial.h> // Arduino IDE <1.6.6
#include <PZEM004T.h>

PZEM004T pzem(2,3);  // RX,TX
IPAddress ip(192,168,1,1);

void setup() {
  Serial.begin(9600);
  pzem.setAddress(ip);
}

void loop() {
  float v = pzem.voltage(ip);
  //if (v < 0.0) v = 0.0;
  Serial.print(v);Serial.print("V; ");

  float i = pzem.current(ip);
  if(i >= 0.0){ Serial.print(i);Serial.print("A; "); }

Serial.print(i);Serial.print("A; ");
  
  float p = pzem.power(ip);
  if(p >= 0.0){ Serial.print(p);Serial.print("W; "); }
  
Serial.print(p);Serial.print("W; ");  
 
  float e = pzem.energy(ip);
  if(e >= 0.0){ Serial.print(e);Serial.print("Wh; "); }
  
Serial.print(e);Serial.print("Wh; ");

  Serial.println();

//  delay(1000);
}
  1. The library is the one downloaded from GitHub - olehs/PZEM004T: Arduino communication library for Peacefair PZEM-004T Energy monitor

UPDATE. I just tried now the code from the example of PZEM library, which uses the hardware serial and connected the pins to RX and TX pin of arduino, and now I can see the voltage !!! Really really happy I can see something now :slight_smile: But I need to make it work with software serial too, as on the ESP8266 (Wemos D1 mini) that is what I need, or it should work using this line on ESP too ?

PZEM004T pzem(&Serial1);

Hi folks.

I'm probably too late for sibianul but I had the same problem using the Arduino Mega on hard serial.

I solved it by using Serial3.
(change the mega connections to 14 & 15 and replace &Serial1 with &Serial3 in the sketch)
This worked fine for me.

Hope this helps somebody.

Hi there,
me again.

Just a word of warning when using the PZEM-004T.
Most of the circuit is live to the mains!
To minimise risk be sure to connect the AC mains with Live to terminal 1 (the outside one) and neutral to terminal 2. That way most of the circuit board is at mains Neutral potential.
You've still got 1 leg of the yellow capacitor Live but most of the rest of the circuit won't give you a shock.

I know this has been mentioned on other forums but it's still worth re-iterating.

Stay safe :slight_smile:

Electra tengo un problema yo tambien estoy igual con el sensor siempre me arroja -1

Hello all, there is a lot of confusion about PZEM-004T module on the internet,
first, check the version on the module and then try to debug the problem.

After a detailed search and time spent I collected its complete information about it, Plese check my Blog where I posted its connection and Arduino code for V3 module of PZEM-004T.

Link:PZEM-004T V3 Module | Arduino & NodeMCU Code, Circuit, Pinout And Library