Flashing message on LCD screen

Hey guys!
I have a problem with my code for displaying Temeperature and Humidity data (sensor is DHT11) on an 16x2 LCD screen (although mine has a module underneath with only 4 pins).

First of all the code isn’t mine. I modified the project, adding on the breadboard a blue,green and red LED for LOW,MEDIUM and HIGH temperature values. I’ve also added to the code to print the “LOW,MED and HIGH” words next to the “Temp” word but my problem is that every 1 sec these words flash for a little (I guess less than 10ms) beofre it refreshes. I want to make these flashes dissapear. I understand that in the void loop it starts all over again and that these flashes make sense due to the code but is there any solution to that? (I uploaded a zip video file showing my problem)
Also, is there any simplest method to clear the words “LOW”, “MED” and “HIGH” every time it detects different parameters (t>25, t<25 && t>22 and t<22) without writing all these:

lcd.setCursor(5,0);
lcd.print(" “);
lcd.setCursor(6,0);
lcd.print(” “);
lcd.setCursor(7,0);
lcd.print(” “);
lcd.setCursor(8,0);
lcd.print(” “);
lcd.setCursor(9,0);
lcd.print(” ");

Anyway, this is the code:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include “DHT.h”

#define DHTPIN 2 // Sesnor Pin
#define DHTTYPE DHT11 // define the type of sensor used

DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor.

LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 in PCF8574 by NXP and Set to 0x3F in PCF8574A by Ti

int redLED=7;
int blueLED=5;
int greenLED=10;
int BUZZER=8;

byte degreec[ ] =
{
B11000,
B11000,
B00011,
B00100,
B00100,
B00100,
B00011,
B00000
};

void setup()
{
pinMode(5,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(10,OUTPUT);
digitalWrite(redLED,LOW);
digitalWrite(blueLED,LOW);
digitalWrite(greenLED,LOW);
digitalWrite(BUZZER,LOW);

pinMode(3,OUTPUT);
digitalWrite(3,HIGH);
lcd.init();
lcd.backlight();
lcd.createChar(0, degreec);
lcd.home();
dht.begin();
lcd.setCursor(0,0);
lcd.print(“Initializing”);
delay(1000);
lcd.setCursor(12,0);
lcd.print(".");
delay(1000);
lcd.setCursor(13,0);
lcd.print(".");
delay(1000);
lcd.setCursor(14,0);
lcd.print(".");
delay(1000);
lcd.setCursor(12,0);
lcd.print(" “);
lcd.setCursor(13,0);
lcd.print(” “);
lcd.setCursor(14,0);
lcd.print(” “);
delay(1000);
lcd.setCursor(12,0);
lcd.print(”.");
delay(1000);
lcd.setCursor(13,0);
lcd.print(".");
delay(1000);
lcd.setCursor(14,0);
lcd.print(".");
delay(1000);
lcd.setCursor(12,0);
lcd.print(" “);
lcd.setCursor(13,0);
lcd.print(” “);
lcd.setCursor(14,0);
lcd.print(” “);
delay(1000);
lcd.setCursor(12,0);
lcd.print(”.");
delay(1000);
lcd.setCursor(13,0);
lcd.print(".");
delay(1000);
lcd.setCursor(14,0);
lcd.print(".");
delay(1000);
lcd.setCursor(0,1);
lcd.print(“Task complete”);
delay(1500);
lcd.setCursor(0,0);
lcd.print(" “);
lcd.setCursor(0,1);
lcd.print(” ");
delay(100);

}

void loop()
{
float h = dht.readHumidity(); // Read Humidity
float t = dht.readTemperature(); // Read temperature as Celsius
lcd.setCursor(0,0);
lcd.print(“Temp:”);
lcd.setCursor(10,0);
lcd.print(t);
lcd.setCursor(15,0);
lcd.write(degreec);
lcd.setCursor(0,1);
lcd.print(“Humd:”);
lcd.setCursor(10,1);
lcd.print(h);
lcd.setCursor(15,1);
lcd.print("%");

if(t>25)
{
lcd.setCursor(5,0);
lcd.print(" “);
lcd.setCursor(6,0);
lcd.print(” “);
lcd.setCursor(7,0);
lcd.print(” “);
lcd.setCursor(8,0);
lcd.print(” “);
lcd.setCursor(9,0);
lcd.print(” “);
lcd.setCursor(5,0);
lcd.print(“HIGH”);
digitalWrite(redLED,HIGH);
digitalWrite(greenLED,LOW);
digitalWrite(blueLED,LOW);
digitalWrite(BUZZER,HIGH);
delay(500);
digitalWrite(redLED,LOW);
digitalWrite(BUZZER,LOW);
delay(500);
}
else if(t<25 && t>22)
{
lcd.setCursor(5,0);
lcd.print(” “);
lcd.setCursor(6,0);
lcd.print(” “);
lcd.setCursor(7,0);
lcd.print(” “);
lcd.setCursor(8,0);
lcd.print(” “);
lcd.setCursor(9,0);
lcd.print(” ");

digitalWrite(BUZZER,LOW);
digitalWrite(redLED,LOW);
digitalWrite(blueLED,LOW);
digitalWrite(greenLED,HIGH);
lcd.setCursor(5,0);
lcd.print(“MED”);
delay(1000);
}
else if(t<22)
{
lcd.setCursor(5,0);
lcd.print(" “);
lcd.setCursor(6,0);
lcd.print(” “);
lcd.setCursor(7,0);
lcd.print(” “);
lcd.setCursor(8,0);
lcd.print(” “);
lcd.setCursor(9,0);
lcd.print(” ");
lcd.setCursor(5,0);
lcd.print(“LOW”);
digitalWrite(redLED,LOW);
digitalWrite(greenLED,LOW);
digitalWrite(BUZZER,HIGH);
digitalWrite(blueLED,HIGH);
delay(500);
digitalWrite(BUZZER,LOW);
digitalWrite(blueLED,LOW);
delay(500);
}
}

VID_20210419_121954 LCD blinking.zip (2,2 MB)

lcd.clear()

seems awkward and inefficient that the code seems to individually replace each character being displayed with a space instead of clearing the entire display

1 Like

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled “How to use this Forum”.
OR

Then look down to “code problems” about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks… Tom… :grinning: :+1: :coffee: :australia:

1 Like

You’re right about that. I don’t know why I programmed it like that (I added this particular part by myself). I’ll change it, thanks a lot.

Okay I’ll do that, thanks for the tip!

lcd.setCursor(5,0);
lcd.print(" “);
lcd.setCursor(6,0);
lcd.print(” “);
lcd.setCursor(7,0);
lcd.print(” “);
lcd.setCursor(8,0);
lcd.print(” “);
lcd.setCursor(9,0);
lcd.print(” ");

The curser moves forward by itself when a character is written. To clear five spaces you can use

lcd.setCursor(5,0);
lcd.print("     ");//5 blank spaces

To avoid flickering with the display, only write information when it changes, not every pass through loop.

Also, unchanging text like Temp and Humid can be written only once in setup. The display has internal memory to hold them.

1 Like

Got it! Thanks for the “clear” function. But the other thing you said, “To avoid flickering with the display, only write information when it changes, not every pass through loop.”, how is it gonna work? Because I need to replace the word “LOW, GOOD or HIGH” depending on the value of the temperature. If I don’t give a replacement then i.e. If the temperature is GOOD and then goes LOW then the letters will stuck on each other.

Yes, only when the temperature changes to a different region, you will clear the previous word and write the new one.

So how can I do that?With what command? I’m so confused

First off, understand that there isn’t a single, obvious command for everything that needs done. One normally has to use a building block approach and add elementary pieces, in the correct order, until the desired effect comes about.

See reply #6. Select a position, write a sequence of spaces, select the position again, write your value.

What happens if t equals 25?

I get it, thanks. Well, about the “t equals 25”, I changed the code and added the missing values of temperature but thank you anyway.

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