Humidity sensor activated relay

Hi,

I want to control a relay using the humidity sensor. Everything works fine, the relay turns on when the humidity is below 60% and turns off when it is above 70%.

The problem is that the code doesn't resume itself unless the relay is off. Let's say I turn my Arduino on. It'll make the initial reading, display it on the screen. If the humidity level is below 60%, then it'll be stuck on those values until the humidity reaches 70%. I hope I make sense. I want the temperature and humidity to be checked every and displayed every 2 seconds regardless of the state of the relay. How do I do that? Thanks. I've added my code. Feel free to edit it to make it more efficient.

// DHT sensor library - Version: Latest 
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>
#define DHTPIN 12     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11  
DHT dht(DHTPIN, DHTTYPE);



//Declaring the lcd pins

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);



//variables
int check;
float hum;  //Stores humidity value
float temp; //Stores temperature value


void setup() {
// Don't forget to choose 9600 at the port screen
  pinMode(11,OUTPUT);
  digitalWrite(11,HIGH);
  
//Telling our lcd to start up
  
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(4,0);
  lcd.print("Reading");
  lcd.setCursor(2,1);
  lcd.print("DHT11 Sensor");
  
  delay(2000);
   
   }

void loop() {

  //These serial codes are for getting readings on the port screen aswell as the LCD display, since they'll offer us a more detailed interface
  
    //Read DHT11 data and store it to variables hum and temp
  hum = dht.readHumidity();
  temp = dht.readTemperature();

  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Temp: ");
  lcd.print(temp);
  lcd.print(" ");
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Hum:  ");
  lcd.print(hum);
  lcd.print(" %");
  

   if (hum < 60){
    while(hum < 75){
    digitalWrite(11,HIGH); //high means on. if the humidity is below 60, the relay will turn on.
  delay(2000);
      }
}
else if (hum > 70){
    digitalWrite(11,LOW);//low means off. if the humidity is above 70, the relay will turn off.
    delay(2000); //Delay 2 sec.
  
  
}
}

Get rid of the while statement.

Thanks... That was simple! :roll_eyes: