PZEM004T LCD I2C 20 x 4

Hello all

I made a project with a PZEM 004T sensor and a 20 x 4 I2C LCD. When there is input voltage, the lcd can read voltage, current and frequency well, but when the voltage is removed, the lcd does not display the number 0 perfectly, moreover the frequency, the lcd does not write down number 0, but number 50hz. how to make lcd not display last data before no voltage?

why does the lcd not display the number 0, while the voltage has been removed?

if you want to display the number 0, then the arduino must be reset

I will upload the program, but sorry if it's messy

#include <PZEM004Tv30.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
float V1;
float C2;
float F3;
unsigned long tm = millis();
unsigned long maxtm = 3000 ;

#if !defined(PZEM_RX_PIN) && !defined(PZEM_TX_PIN) //Arduino
#define PZEM_RX_PIN 2 // Pin 2 Rx Arduino ke Pin Tx Pzem
#define PZEM_TX_PIN 3 // Pin 3 Tx Arduino ke Pin Rx Pzem
#endif
#define RELAY_1 4

SoftwareSerial pzemSWSerial(PZEM_RX_PIN, PZEM_TX_PIN);
PZEM004Tv30 pzem(pzemSWSerial);
void setup() {

    Serial.begin(115200);
    pinMode(RELAY_1, OUTPUT); //Relay
    lcd.init();                      // initialize the lcd
    lcd.backlight();
    lcd.setCursor(0,0);
    lcd.print("anjai mabar"); 
    {
    delay(1000);
    lcd.clear();
    }
}

void loop(){
         
    Serial.print("Custom Address:");
    Serial.println(pzem.readAddress(), HEX);
        
    float voltage = pzem.voltage();
    if (!isnan(voltage)){
      V1 = voltage;
      Serial.print("Tegangan");Serial.print(V1);Serial.println("V");
    }else{
      V1 = 0.0;
      Serial.print("Tegangan");Serial.print(V1);Serial.println("V");
    }

    lcd.setCursor(0,1);lcd.print("Tegangan : ");
    lcd.setCursor(10,1);lcd.print(V1);
    lcd.setCursor(17,1);lcd.print("V");
    
    if(V1 < 220)
    {
    digitalWrite(4, LOW);
    lcd.setCursor(0,1);
    }else if (V1 > 221){
    digitalWrite(4, HIGH);
    }

    float current = pzem.current();
    if (!isnan(current)){
      C2 = current;
      Serial.print("Arus");Serial.print(C2);Serial.println("A");
    }else{
      C2 = 0.0;
      Serial.print("Arus");Serial.print(C2);Serial.println("A");
    }

    lcd.setCursor(0,2);lcd.print("Arus     : ");
    lcd.setCursor(10,2);lcd.print(C2);
    lcd.setCursor(17,2);lcd.print("A");

    float frequency = pzem.frequency();
    if (!isnan(frequency)){
      F3 = frequency;
      Serial.print("Frekuensi");Serial.print(F3);Serial.println("Hz");
    }else{
      F3 = 0.0;
      Serial.print("Frekuensi");Serial.print(F3);Serial.println("Hz");
    }

    lcd.setCursor(0,3);lcd.print("Frekuensi: ");
    lcd.setCursor(10,3);lcd.print(F3);
    lcd.setCursor(17,3); lcd.print("Hz");

    Serial.println();
    delay(2000);
}
  

Apparently, this library returns NaN whenever an update failed.

Instead of assuming the result is 0V, perhaps you can use the previous value instead.

@fluks, do not cross-post. Vomit cleaned up.

That's what You should expect when nothing is connected. Use a pull down resistor to GND. Else the input acts like an antenna picking up any noice in the air.

does the pull down resistor require a push button?

No. As a first try, use 10 kOhm. Connect the resistor between the input and GND.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.