-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESP32 Serial2 + 14 PZEM-004T Sensor Module #92
Comments
Check LINKS section for additional information. ESP's gpio pin can't drive many opto's in parallel due to current limitation. You need HW MOD something like this. Or if you do not like modding many pzems it could be better to use external bipolar transistors of FETs to drive serial line (i.e. like here ) If you use esp32 than you might wanna check async event-driven library for communicating with multiple pzem devs. |
Thank Vortigont for your comment, it's not possible for me to mod the R8 into 300-500k ohm, so the possibility is to remove the R4 yeah? So I removing 13 of 14 PZEM R4's right? |
Or I use all 3 serial ports of ESP. So each port connect to 5 PZEMs. It's tolerated? Sorry for my messy type |
R8 and R4 pulls different lines - rx and tx. You can't tune one and omit the other. It might be OK to pull more than 5 devices with only removing R4, but I'm not sure for how many. You can experiment. |
possible, but it may be unstable. Too close to the edge :) |
Is there any problem if I connect the L-N of PZEM with 2 of 3 phase wire (RST)? The actual is
|
Because while I protoyping with 14 PZEM Sensor, the connection of L-N of PZEM is R-N (neutral), and there is no problem with serial connection |
@MFayH quite a nice setup :) |
RST I mean Phase 1 phase 2 and phase 3 I'm sorry for that :). |
Can you give example circuit for the transistor? It's very helpful |
Now I got your point. You mean feed PZEM with phase-to-phase wires. That's a good question actually. I see this issues for such a setup
Pls, keep us posted if u dare to try this setup. I'm really interested with the outcome :) |
The pzem is designed to work at 120vac or 240vac, Phase and Neutral. In other words: In your case you are running of an RST transformer without the Neutral, effectively a Delta system. Even if your nominal voltage is below 240vac for example I doubt you'll getting anything out of it. But like @vortigont mentioned, it would be interesting to see what you get out of it. Just be safe and ask an electrician if you are uncertain. Good luck 👍 |
Yes you all @vortigont @Nismonx got my point about phase-to-phase connection that I have installed. I think isn't affected to the PZEM because the voltage is in range 80~260V AC. but I'll try to connect again with Phase-to-Neutral as my protoyping before.
Appreciate to you all for excited to this issue. Thanks |
And when I try to call all of my PZEM (void) this is happen
But, when I call just 6 PZEM (void) with 5 PZEM connected to ESP32. It's work fine. Any comments? |
Is this because network connection code? I use <Wifi.h> and <HTTPClient.h> library to send the data to database. |
What do you mean |
I mean call PZEM read function
|
Update of this issue. I add wiring for changeover relay for separate RX pin of ESP32 to read from sensor 5 by 5 until 13 sensors. 1-10 sensors are working properly, but 11th to 13th sensor said "Sensor Error Measuring". I have flush the serial pin and begin again, but doesn't work. Any suggest? |
The push button symbol just for simulation. The actual R1 activated by GPIO 18 and R2 activated by GPIO 19 of ESP32 |
Thank you everyone. Problem has solved.
Very pleasure interact with amazing guys like you. Thanks in advance |
Same problem, I only receive two measurements regardless of the directions of each sensor. |
Hi everyone. I try to read 14 PZEM-004T Sensor Module with single serial port (Serial2, RX16, TX17). But it like there is a limit for connections. just can communicate 5 sensors module randomly from 14 sensors. So if I connect the 6th sensor, the respon in serial monitor is "Sensor Error Measuring". There is any limitation of connection in Serial port? Any solution for it? Thank you before
There is my program (long, but similar, just different variables and sensor address)
`
#include <PZEM004Tv30.h>
#include <WiFi.h>
#include <HTTPClient.h>
HTTPClient http;
#define PZEM_RX_PIN 16
#define PZEM_TX_PIN 17
#define PZEM_SERIAL Serial2
#define NUM_PZEMS 13
PZEM004Tv30 pzems[NUM_PZEMS];
const char WIFI_SSID[] = "OPPO Reno6 Pro 5G";
const char WIFI_PASSWORD[] = "34567890";
void setup() {
Serial.begin(9600);
//
// For each PZEM, initialize it
for(int i = 0; i < NUM_PZEMS; i++) {
pzems[i] = PZEM004Tv30(PZEM_SERIAL, PZEM_RX_PIN, PZEM_TX_PIN, 0x01 + i);
}
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected WiFi with IP Address: ");
Serial.println(WiFi.localIP());
}
float calib = 3.5;
float vGVDMain, cGVDMain, pGVDMain, eGVDMain, fGVDMain, pfGVDMain;
float vGVDClean, cGVDClean, pGVDClean, eGVDClean, fGVDClean, pfGVDClean;
float vRVD901, vSVD901, vTVD901, cRVD901, cSVD901, cTVD901, pRVD901, pSVD901, pTVD901, eRVD901, eSVD901, eTVD901, fRVD901, fSVD901, fTVD901, pfRVD901, pfSVD901, pfTVD901;
float vRVD301, vSVD301, vTVD301, cRVD301, cSVD301, cTVD301, pRVD301, pSVD301, pTVD301, eRVD301, eSVD301, eTVD301, fRVD301, fSVD301, fTVD301, pfRVD301, pfSVD301, pfTVD301;
float vRPRC, vSPRC, vTPRC, cRPRC, cSPRC, cTPRC, pRPRC, pSPRC, pTPRC, eRPRC, eSPRC, eTPRC, fRPRC, fSPRC, fTPRC, pfRPRC, pfSPRC, pfTPRC;
float vRPMB, vSPMB, vTPMB, cRPMB, cSPMB, cTPMB, pRPMB, pSPMB, pTPMB, eRPMB, eSPMB, eTPMB, fRPMB, fSPMB, fTPMB, pfRPMB, pfSPMB, pfTPMB;
void VD901() {
Serial.print("VD901");
Serial.print(" - Address : ");
Serial.println(pzems[0].getAddress(), DEC);
Serial.println("===================");
vRVD901 = pzems[0].voltage()+calib; vSVD901 = pzems[1].voltage()+calib; vTVD901 = pzems[2].voltage()+calib;
cRVD901 = pzems[0].current(); cSVD901 = pzems[1].current(); cTVD901 = pzems[2].current();
pRVD901 = pzems[0].power(); pSVD901 = pzems[1].power(); pTVD901 = pzems[2].power();
eRVD901 = pzems[0].energy(); eSVD901 = pzems[1].energy(); eTVD901 = pzems[2].energy();
fRVD901 = pzems[0].frequency(); fSVD901 = pzems[1].frequency(); fTVD901 = pzems[2].frequency();
pfRVD901 = pzems[0].pf(); pfSVD901 = pzems[1].pf(); pfTVD901 = pzems[2].pf();
if(isnan(vRVD901)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage R : "+String(vRVD901)+"V");
Serial.print("Current R : "+String(cRVD901)+"A");
Serial.print("Power R : "+String(pRVD901)+"W");
Serial.print("Energy R : "+String(eRVD901, 3)+"kWh");
Serial.print("Freq R : "+String(fRVD901, 1)+"Hz");
Serial.println("PF R : "+String(pfRVD901));
}
if(isnan(vSVD901)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage S : "+String(vSVD901)+"V");
Serial.print("Current S : "+String(cSVD901)+"A");
Serial.print("Power S : "+String(pSVD901)+"W");
Serial.print("Energy S : "+String(eSVD901, 3)+"kWh");
Serial.print("Freq S : "+String(fSVD901, 1)+"Hz");
Serial.println("PF S : "+String(pfSVD901));
}
Serial.println("-------------------");
Serial.println();
http.begin("http://192.168.227.118/moniHLT/VD901.php?vR="+String(vRVD901)+"&cR="+String(cRVD901)+"&pR="+String(pRVD901)+"&eR="+String(eRVD901)+"&fR="+String(fRVD901)+"&pfR="+String(pfRVD901)+"&vS="+String(vSVD901)+"&cS="+String(cSVD901)+"&pS="+String(pSVD901)+"&eS="+String(eSVD901)+"&fS="+String(fSVD901)+"&pfS="+String(pfSVD901)+"&vT="+String(vTVD901)+"&cT="+String(cTVD901)+"&pT="+String(pTVD901)+"&eT="+String(eTVD901)+"&fT="+String(fTVD901)+"&pfT="+String(pfTVD901));
int httpCode = http.GET();
if(httpCode > 0) {
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
void VD301() {
Serial.print("VD301");
Serial.print(" - Address : ");
Serial.println(pzems[3].getAddress(), DEC);
Serial.println("===================");
vRVD301 = pzems[3].voltage()+calib; vSVD301 = pzems[4].voltage()+calib; vTVD301 = pzems[5].voltage()+calib;
cRVD301 = pzems[3].current(); cSVD301 = pzems[4].current(); cTVD301 = pzems[5].current();
pRVD301 = pzems[3].power(); pSVD301 = pzems[4].power(); pTVD301 = pzems[5].power();
eRVD301 = pzems[3].energy(); eSVD301 = pzems[4].energy(); eTVD301 = pzems[5].energy();
fRVD301 = pzems[3].frequency(); fSVD301 = pzems[4].frequency(); fTVD301 = pzems[5].frequency();
pfRVD301 = pzems[3].pf(); pfSVD301 = pzems[4].pf(); pfTVD301 = pzems[5].pf();
if(isnan(vRVD301)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage R : "+String(vRVD301)+"V");
Serial.print("Current R : "+String(cRVD301)+"A");
Serial.print("Power R : "+String(pRVD301)+"W");
Serial.print("Energy R : "+String(eRVD301, 3)+"kWh");
Serial.print("Freq R : "+String(fRVD301, 1)+"Hz");
Serial.println("PF R : "+String(pfRVD301));
}
if(isnan(vSVD301)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage S : "+String(vSVD301)+"V");
Serial.print("Current S : "+String(cSVD301)+"A");
Serial.print("Power S : "+String(pSVD301)+"W");
Serial.print("Energy S : "+String(eSVD301, 3)+"kWh");
Serial.print("Freq S : "+String(fSVD301, 1)+"Hz");
Serial.println("PF S : "+String(pfSVD301));
}
Serial.println("-------------------");
Serial.println();
http.begin("http://192.168.110.118/moniHLT/VD301.php?vR="+String(vRVD301)+"&cR="+String(cRVD301)+"&pR="+String(pRVD301)+"&eR="+String(eRVD301)+"&fR="+String(fRVD301)+"&pfR="+String(pfRVD301)+"&vS="+String(vSVD301)+"&cS="+String(cSVD301)+"&pS="+String(pSVD301)+"&eS="+String(eSVD301)+"&fS="+String(fSVD301)+"&pfS="+String(pfSVD301)+"&vT="+String(vTVD301)+"&cT="+String(cTVD301)+"&pT="+String(pTVD301)+"&eT="+String(eTVD301)+"&fT="+String(fTVD301)+"&pfT="+String(pfTVD301));
int httpCode = http.GET();
if(httpCode > 0) {
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
void PRC003A() {
Serial.print("PRC-003A");
Serial.print(" - Address : ");
Serial.println(pzems[6].getAddress(), DEC);
Serial.println("===================");
vRPRC = pzems[6].voltage()+calib; vSPRC = pzems[7].voltage()+calib; vTPRC = pzems[8].voltage()+calib;
cRPRC = pzems[6].current(); cSPRC = pzems[7].current(); cTPRC = pzems[8].current();
pRPRC = pzems[6].power(); pSPRC = pzems[7].power(); pTPRC = pzems[8].power();
eRPRC = pzems[6].energy(); eSPRC = pzems[7].energy(); eTPRC = pzems[8].energy();
fRPRC = pzems[6].frequency(); fSPRC = pzems[7].frequency(); fTPRC = pzems[8].frequency();
pfRPRC = pzems[6].pf(); pfSPRC = pzems[7].pf(); pfTPRC = pzems[8].pf();
if(isnan(vRPRC)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage R : "+String(vRPRC)+"V");
Serial.print("Current R : "+String(cRPRC)+"A");
Serial.print("Power R : "+String(pRPRC)+"W");
Serial.print("Energy R : "+String(eRPRC, 3)+"kWh");
Serial.print("Freq R : "+String(fRPRC, 1)+"Hz");
Serial.println("PF R : "+String(pfRPRC));
}
if(isnan(vSPRC)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage S : "+String(vSPRC)+"V");
Serial.print("Current S : "+String(cSPRC)+"A");
Serial.print("Power S : "+String(pSPRC)+"W");
Serial.print("Energy S : "+String(eSPRC, 3)+"kWh");
Serial.print("Freq S : "+String(fSPRC, 1)+"Hz");
Serial.println("PF S : "+String(pfSPRC));
}
Serial.println("-------------------");
Serial.println();
http.begin("http://192.168.110.118/moniHLT/PRC.php?vR="+String(vRPRC)+"&cR="+String(cRPRC)+"&pR="+String(pRPRC)+"&eR="+String(eRPRC)+"&fR="+String(fRPRC)+"&pfR="+String(pfRPRC)+"&vS="+String(vSPRC)+"&cS="+String(cSPRC)+"&pS="+String(pSPRC)+"&eS="+String(eSPRC)+"&fS="+String(fSPRC)+"&pfS="+String(pfSPRC)+"&vT="+String(vTPRC)+"&cT="+String(cTPRC)+"&pT="+String(pTPRC)+"&eT="+String(eTPRC)+"&fT="+String(fTPRC)+"&pfT="+String(pfTPRC));
int httpCode = http.GET();
if(httpCode > 0) {
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
void PMB001C() {
Serial.print("PMB-001C");
Serial.print(" - Address : ");
Serial.println(pzems[9].getAddress(), DEC);
Serial.println("===================");
vRPMB = pzems[9].voltage()+calib; vSPMB = pzems[10].voltage()+calib; vTPMB = pzems[11].voltage()+calib;
cRPMB = pzems[9].current(); cSPMB = pzems[10].current(); cTPMB = pzems[11].current();
pRPMB = pzems[9].power(); pSPMB = pzems[10].power(); pTPMB = pzems[11].power();
eRPMB = pzems[9].energy(); eSPMB = pzems[10].energy(); eTPMB = pzems[11].energy();
fRPMB = pzems[9].frequency(); fSPMB = pzems[10].frequency(); fTPMB = pzems[11].frequency();
pfRPMB = pzems[9].pf(); pfSPMB = pzems[10].pf(); pfTPMB = pzems[11].pf();
if(isnan(vRPMB)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage R : "+String(vRPMB)+"V");
Serial.print("Current R : "+String(cRPMB)+"A");
Serial.print("Power R : "+String(pRPMB)+"W");
Serial.print("Energy R : "+String(eRPMB, 3)+"kWh");
Serial.print("Freq R : "+String(fRPMB, 1)+"Hz");
Serial.println("PF R : "+String(pfRPMB));
}
if(isnan(vSPMB)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage S : "+String(vSPMB)+"V");
Serial.print("Current S : "+String(cSPMB)+"A");
Serial.print("Power S : "+String(pSPMB)+"W");
Serial.print("Energy S : "+String(eSPMB, 3)+"kWh");
Serial.print("Freq S : "+String(fSPMB, 1)+"Hz");
Serial.println("PF S : "+String(pfSPMB));
}
Serial.println("-------------------");
Serial.println();
http.begin("http://192.168.110.118/moniHLT/PMB.php?vR="+String(vRPMB)+"&cR="+String(cRPMB)+"&pR="+String(pRPMB)+"&eR="+String(eRPMB)+"&fR="+String(fRPMB)+"&pfR="+String(pfRPMB)+"&vS="+String(vSPMB)+"&cS="+String(cSPMB)+"&pS="+String(pSPMB)+"&eS="+String(eSPMB)+"&fS="+String(fSPMB)+"&pfS="+String(pfSPMB)+"&vT="+String(vTPMB)+"&cT="+String(cTPMB)+"&pT="+String(pTPMB)+"&eT="+String(eTPMB)+"&fT="+String(fTPMB)+"&pfT="+String(pfTPMB));
int httpCode = http.GET();
if(httpCode > 0) {
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
void GVDMain() {
Serial.print("GVD Main Vacuum");
Serial.print(" - Address : ");
Serial.println(pzems[12].getAddress(), DEC);
Serial.println("===================");
vGVDMain = pzems[12].voltage()+calib;
cGVDMain = pzems[12].current();
pGVDMain = pzems[12].power();
eGVDMain = pzems[12].energy();
fGVDMain = pzems[12].frequency();
pfGVDMain = pzems[12].pf();
if(isnan(vGVDMain)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage: "+String(vGVDMain)+"V");
Serial.print("Current: "+String(cGVDMain)+"A");
Serial.print("Power : "+String(pGVDMain)+"W");
Serial.print("Energy : "+String(eGVDMain, 3)+"kWh");
Serial.print("Freq : "+String(fGVDMain, 1)+"Hz");
Serial.print("PF : "+String(pfGVDMain));
}
Serial.println("-------------------");
Serial.println();
http.begin("http://192.168.110.118/moniHLT/GVDMain.php?vR="+String(vGVDMain)+"&cR="+String(cGVDMain)+"&pR="+String(pGVDMain)+"&eR="+String(eGVDMain)+"&fR="+String(fGVDMain)+"&pfR="+String(pfGVDMain)); //HTTP
int httpCode = http.GET();
if(httpCode > 0) {
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
void GVDClean() {
Serial.print("GVD Clean Vacuum");
Serial.print(" - Address : ");
Serial.println(pzems[13].getAddress(), DEC);
Serial.println("===================");
vGVDClean = pzems[13].voltage()+calib;
cGVDClean = pzems[13].current();
pGVDClean = pzems[13].power();
eGVDClean = pzems[13].energy();
fGVDClean = pzems[13].frequency();
pfGVDClean = pzems[13].pf();
if(isnan(vGVDClean)){
Serial.println("Sensor Error Measuring");
} else {
Serial.print("Voltage: "+String(vGVDClean)+"V");
Serial.print("Current: "+String(cGVDClean)+"A");
Serial.print("Power : "+String(pGVDClean)+"W");
Serial.print("Energy : "+String(eGVDClean, 3)+"kWh");
Serial.print("Freq : "+String(fGVDClean, 1)+"Hz");
Serial.print("PF : "+String(pfGVDClean));
}
Serial.println("-------------------");
Serial.println();
http.begin("http://192.168.110.118/moniHLT/GVDClean.php?vR="+String(vGVDClean)+"&cR="+String(cGVDClean)+"&pR="+String(pGVDClean)+"&eR="+String(eGVDClean)+"&fR="+String(fGVDClean)+"&pfR="+String(pfGVDClean)); //HTTP
int httpCode = http.GET();
if(httpCode > 0) {
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
void loop() {
VD901();
delay(2000);
VD301();
delay(2000);
PRC003A();
delay(2000);
PMB001C();
delay(2000);
GVDMain();
// delay(2000);
// GVDClean();
Serial.println();
delay(5000);
}
`
The text was updated successfully, but these errors were encountered: