pls verify the sketch

i am beginner, and i am trying to make a hymidity controller with a relay and DHT11 , my intention is to make relay high if the humidity drops below 70 and continues up to 85 and relay becomes low after 85.

my sketch is given below . pls help me.

#include <dht.h>

dht DHT;

#define DHT11_PIN 7
int pinOut = 8;

void setup(){
Serial.begin(9600);
pinMode(8, OUTPUT);
}
int pin0ut = LOW;
void loop()
{
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
if ((DHT.humidity <70) && (pin0ut == LOW)){
digitalWrite(pinOut, HIGH);
}
if ((DHT.humidity >85) && (pin0ut == HIGH)){
digitalWrite(pinOut, LOW);
}
else {
digitalWrite(pinOut, LOW);
}
delay(500);
}

Please read the “How to use this forum” post and carefully follow the directions.

You are comparing pin numbers with HIGH and LOW…

Perhaps you meant

  if (DHT.humidity < 70) {
    digitalWrite (pinOut, HIGH);
  }
  else if (DHT.humidity > 85) {
    digitalWrite (pinOut, LOW);
  }

There no need to avoid writing the same value twice to the same pin, its done all the time.

Trying to have two variables named pinOut with one defined as 8 and the other defined as 0 is probably a bad idea.

#include <dht.h>

dht DHT;

#define DHT11_PIN 7
int pinOut = 8;

void setup(){
  Serial.begin(9600);
  pinMode(8, OUTPUT);
}
int pin0ut = LOW;
void loop()
{
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  if (DHT.humidity <70) {
    digitalWrite(pinOut, HIGH);
  }
   if (DHT.humidity >85){
    digitalWrite(pinOut, LOW);
   }
  
  delay(500);            
}

When humidity drop below 70, relay activate. It deactivate when humidity reach >85. No need for else if you want hysteresis.

Thanks, it was very helpful .it is running perfectly