problem with refresh the information from the DHT

Hi

I’m trying to read from 4 dht11
The problem is that the information from the sensors do not change ,and when i power the arduino the first screen is empty until i push the button .

#include <dht.h>    
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
dht DHT1;
dht DHT2;
#define dht1pin 7      // 7 to dht1pin
#define dht2pin 8      // 8 to dht1pin
int relay_pin = 9;     //9 to relay
int switchPin = 10;   // momentary switch on 10, other side connected to ground
int Display = 0;
LiquidCrystal_I2C lcd (0x27, 16, 2);

byte IN[8]= {                    // Array of bytes
  B00100,                       // B stands for binary formatter and the 5 numbers are the pixels
  B00100,
  B00100,
  B00100,
  B11001,
  B10101,
  B10011,
  B10001,
};
byte OUT[8]= {                  // Array of bytes
  B11100,                      // B stands for binary formatter and the 5 numbers are the pixels
  B10100,
  B11101,
  B00101,
  B00111,
  B11100,
  B01000,
  B01000,
};
byte NEW[8]= {                    // Array of bytes
  B11100,                       // B stands for binary formatter and the 5 numbers are the pixels
  B10100,
  B11100,
  B00110,
  B01001,
  B01000,
  B01001,
  B00110,
};



void setup() {
lcd.init();
lcd.backlight();

 pinMode(switchPin, INPUT);
 digitalWrite(switchPin, HIGH);   //turn on pullup resistor

lcd.createChar(7, IN);         // Create a custom character for use on the LCD. Up to eight characters of 5x8 pixels are supported

lcd.createChar(8, OUT);        

lcd.createChar(9, NEW);        // Create a custom *C

dht begin();

lcd.setCursor(0,0);
lcd.print("Hello Nonta");
delay(3000);
lcd.clear();
lcd.setCursor(0,1);
lcd.print("ARDUINO IS ON");
delay(2000);
lcd.clear();
pinMode(relay_pin, OUTPUT);
digitalWrite(relay_pin, HIGH);
}


/////-----------------------------------------------------------------------------------------------
void loop() {
 if (digitalRead(switchPin) == LOW){
  delay(500);         //delay to debounce switch

  Display ++;       
  if(Display > 3){   //this is for the menu to circle
    lcd.clear();
    Display = 1;
  }
 switch (Display) {
  
  case 1: {
    DHT1.read11(dht1pin);                  //define dht1pin 7
   lcd.setCursor(0,0);                    // Sets the location at which subsequent text written to the LCD will be displayed
   lcd.write(7);                          // Writes a IN to the LCD
   lcd.setCursor(1,0);
   lcd.print("T:");
   lcd.print(DHT1.temperature,1);       //prints  DHT1 the 1 is how many digits after ,
   lcd.print((char)9);
   lcd.setCursor(10,0);
   lcd.print("H:");
   lcd.print(DHT1.humidity,0);
   lcd.print("%");

   
if (DHT1.temperature > 31){
  digitalWrite(relay_pin, LOW);
  lcd.setCursor(15,0); 
  lcd.print("A"); 
  delay(10);
}
else{
  digitalWrite(relay_pin, HIGH);
  lcd.setCursor(15,0); 
  lcd.print("K");
  delay(10); 
}

   lcd.setCursor(0,1);                   
   lcd.write(8);                         // Writes a OUT to the LCD
   DHT2.read11(dht2pin);  
   lcd.setCursor(1,1);
   lcd.print("T:");        
   lcd.print(DHT2.temperature,1);   
   lcd.print((char)9);
   lcd.setCursor(10,1);
   lcd.print("H:");
   lcd.print(DHT2.humidity,0);
   lcd.print("%");
  }
  break;
  
case 2: { 
   lcd.clear();
   lcd.setCursor(1, 0);
   lcd.print("sensor 3");    
  }
   break; 
case 3: {
   lcd.clear();
   lcd.setCursor(1, 1);
   lcd.print("Sensor 4");      
      }
   break;
 }
 }
 }

``[/code]

Change this line:

if (digitalRead(switchPin) == LOW){

To this:

if ((Display == 0) || (digitalRead(switchPin) == LOW)){

EDIT: Corrected a brain fart..

thank you Danois90 ,you solve one off my broblem .you have any idea how to refresh the information on case 1

Nondas:
thank you Danois90 ,you solve one off my broblem .you have any idea how to refresh the information on case 1

Of course I do.. Just not understanding the question I also do..

Nondas:
I’m trying to read from 4 dht11

#include <dht.h>    

dht DHT1;
dht DHT2;
#define dht1pin 7      // 7 to dht1pin
#define dht2pin 8      // 8 to dht1pin

Am I missing something?- you say you want to read from 4, but only seem to have 2 in the code.

havingFunSoFar 8) no you do not missing anything ,i want to put 4 but now i have 2. 8)

the problem is that read the information from dht1 and dht2 post it on the lcd ,but do not change if the temp or the hum chance ,only if i push the button and make a circle on the menu

You should create a method that takes a DHT as argument and print the information from that method. This would enable you to only change the DHT passed as argument in the switch statement instead of repeating all the code for each DHT. Your next question: "And how do I do that?". My next answer: "Stop asking, start coding!" :wink:

EDIT: Changed "void" to "method" to silence the kids.

Danois90:
You should create a void

What's that?

Danois90:
EDIT: Changed "void" to "method" to silence the kids.

If by that you mean someone who prefers to use the correct terminology....

thank you ,i will try to code it