Running fan and pump with the dht value

I was trying to run the fan when when the temperature is between 20 and 40 With this and next the statement is to open pump when the temperature is above 40 and the humidity is less than 50.Now the problem my pump is not working

this is my code Can anyone help to come out of this. it would be great

#include <dht.h>
#define dht_apin A0 // Analog Pin sensor is connected to
 
dht DHT;

  int led=7;
 int Motor=11;
 
void setup(){
 pinMode(dht_apin,INPUT);
  Serial.begin(9600);
  delay(500);//Delay to let system boot
  Serial.println("DHT11 Humidity & temperature Sensor\n\n");
  delay(1000);//Wait before accessing Sensor
 pinMode(Motor,OUTPUT);
  pinMode(led,OUTPUT);
}//end "setup()"
 
void loop(){
  //Start of Program 
 
    int readData = DHT.read11(dht_apin); // Reads the data from the sensor
  int t = DHT.temperature; // Gets the values of the temperature
  int h = DHT.humidity; // Gets the values of the humidity
  
  // Printing the results on the serial monitor
  Serial.print("Temperature = ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print("    Humidity = ");
  Serial.print(h);
  Serial.println(" % ");
    
    delay(5000);//Wait 5 seconds before accessing sensor again.
 
  //Fastest should be once every two seconds.
 if((15<t<40)or(50<h<85))
 {
 digitalWrite(led,HIGH);
 digitalWrite(Motor,LOW);
 delay(1000);
 }
 else if((t>30)&&(h<50))
 {
   digitalWrite(Motor,HIGH);
   digitalWrite(led,LOW);
   delay(1000);
   }
   else
   {
    digitalWrite(Motor,LOW);
   digitalWrite(led,LOW);
   delay(5000);
    }
}

Start by reading this:

and restructuring your code as described in the article.

When it comes to debugging nested if statements, it’s often best to add some Serial.print statements to show which branches of the if statement have been evaluated as true.

Pete.

so i supposed to put all the statement in the loop

For example
`

void RelayOff() {
digitalWrite(9, LOW);
}

void RelayOn() {
digitalWrite(9, HIGH);
}

void Temperaturmessung(){
     
  sensors.requestTemperatures();
  tempout = (sensors.getTempCByIndex(0));
  Serial.print (String ("Temperatur ist : ") + sensors.getTempCByIndex(0));
 Blynk.virtualWrite(V4, tempout);
 if((RelayOn == 1 && RelayOff ==0)&&(tempout <26)){ 
    digitalWrite(9, HIGH);
    }
    else if(tempout >26){ 
    digitalWrite(9, LOW);
}
}


 
void loop()
{
  Blynk.run();
  timer.run();
}
``

don’t forget timer in setup :wink:

1 Like

Thanks a lot :blush::+1:

1 Like

and remove the delays , else you 'll flood blynk server :wink: