I have ordered from Ali express dated 30-06-2025, however, Arduino library gives error regarding header/library file.
I also consult from chatGPT, its suggest that V4.0 library is not available officially from Arduino.
Does anyone have idea regarding the matter?
Hi @adnanchana.
Please provide the full and exact text of the error message.
You need to give us more information.
What Arduino and IDE version we're talking about?
What library (together with the version) you have installed, and how (library manager? A zip? What?)
What is the sketch you're testing the sensor with? Does the library come with examples, and have you tried one?
What is exactly the error about header files (when compiling)?
Compilation error: PZEM004Tv40.h: No such file or directory
#include <PZEM004Tv40.h>
#include <HardwareSerial.h>
// ESP32: RX = GPIO4, TX = GPIO15
#define RX_PIN 2
#define TX_PIN 15
// Create UART1
HardwareSerial PZEMSerial(1);
PZEM004Tv40 pzem(&PZEMSerial);
void setup() {
Serial.begin(115200);
delay(1000);
// Begin UART1 on GPIO4 (RX) and GPIO15 (TX)
PZEMSerial.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN);
Serial.println("PZEM-004T v4.0 Reader Started...");
}
void loop() {
float voltage = pzem.voltage();
float current = pzem.current();
float power = pzem.power();
float energy = pzem.energy();
float frequency = pzem.frequency();
float pf = pzem.pf();
if (isnan(voltage)) {
Serial.println(" Error: Could not read from PZEM.");
} else {
Serial.printf("Voltage : %.1f V\n", voltage);
Serial.printf("Current : %.3f A\n", current);
Serial.printf("Power : %.1f W\n", power);
Serial.printf("Energy : %.2f Wh\n", energy);
Serial.printf("Frequency : %.1f Hz\n", frequency);
Serial.printf("Power Factor: %.2f\n", pf);
Serial.println("-------------------------------");
}
delay(1000);
}
after compile it error Compilation error: PZEM004Tv40.h: No such file or directory
Did you find this code somewhere on the Internet, or base it on code you found on the Internet?
If yes, please provide a link to where you found it. That will provide the forum helpers with valuable context that will allow us to more effectively assist you.
Even without a sensor to test the problem, I installed the PZEM004Tv30 library rev. 1.2.1 from the library manager, and compiled the "PZEMsoftwareSerial" without any error so any library/header error should be checked with the library installation and/or the sketch used.
This found from ChatGPT.
Don't know anything about V40, it isn't available via Library Manager!
I recommend you to install v30 from there and see if changing reference you can compile and run tht code.
PS: when in doubt about a library, always check the examples first: if are ok the library should be ok, if not, the library is bad (especially if downloaded/installed "by hand").
but I have Version 4.0 of PZEM004T, it is updated version introduced in the market.
OK, that explains it. ChatGPT is prone to "hallucinations". So it will tell you complete lies and give you garbage code. You must use a reliable source of information for your projects.
Never trust ChatGPT because it can fail and give you code apparently good but it very often needs some changes and corrections. This means you can use it only if you're experienced enough to be able to identify and correct the mistakes ChatGPT makes. If you aren't much an Arduino expert, you can often face this kind of frustrating situations.
The only thing I can say is try v30 installed from the Library manager then change the #include to point to that version and see if it works.
ok, do you have any idea regarding updated Library Version of PZEM004T V4.0?
Since not only you have not yet answered my questions (which Arduino? which IDE?) but you have not yet specified where you downloaded the library from (IF you downloaded it... Did you?) how can we tell you if there is an updated version?
I suspect that you are not very experienced with Arduino, so I'm sorry to say that thinking of using only ChatGPT without studying a little is completely useless, indeed harmful for you. Install that v30 from the library, the run a couple of examples to see everything is working, but then you need to change that crappy ChatGPT code.
thanks for suggestion
There is a good chance the existing library will work fine with the "V4.0" PZEM004T. Just give it a try.
It might be that the version increment was the result of hardware changes that don't have any impact on compatibility with the code. Or it could even be that there is no functional difference between the "3.0" and "4.0" models and this was either done by an unscrupulous manufacturer/seller to try to make their product seem better than the ones sold by competing seller, or perhaps just a typo.