mikroavr

pzem-004 v3 esp32

Nov 13th, 2019
525
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <PZEM004Tv30.h>
  2. #define RXD2 16
  3. #define TXD2 17
  4.  
  5. PZEM004Tv30 pzem_r(&Serial2);
  6.  
  7. float vr;
  8. float ir;
  9. float freq;
  10. float pf_r;
  11. float energy;
  12. float power;
  13.  
  14. void setup() {
  15.   Serial.begin(115200);
  16.   Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
  17. }
  18.  
  19. void loop() {
  20.     baca_pzem();
  21.     Serial.print("Volt: ");Serial.print(vr,2  );Serial.print("V, ");
  22.     Serial.print("curr: ");Serial.print(ir,3);Serial.print("A, ");
  23.     Serial.print("pf: ");Serial.print(pf_r);Serial.println("%, ");
  24.     Serial.print("Power: ");Serial.print(power);Serial.print("W, ");
  25.     Serial.print("Energy: ");Serial.print(energy,3);Serial.print("kWh, ");
  26.     Serial.print("freq: ");Serial.print(freq,1);Serial.println("Hz, ");
  27.     Serial.println();
  28.     delay(2000);
  29. }
  30.  
  31. void baca_pzem(){
  32.     vr = pzem_r.voltage();
  33.     ir = pzem_r.current();
  34.     freq = pzem_r.frequency();
  35.     pf_r = pzem_r.pf();
  36.     power = pzem_r.power();
  37.     energy = pzem_r.energy();
  38. }
RAW Paste Data