DHT11

Hello all
There is a problem with the use of a humidity & temperature sensor DHT11
The relay shield does not respond to changes in sensor value
Is it wrong to write code in this way?
Please Help
The code used is:
#include <LiquidCrystal.h>

#include <dht.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int greenPin = A0;
dht sensor;
int fan=9;
int pump=8;
float x,y;
void setup()
{
pinMode(pump,OUTPUT);
pinMode(fan,OUTPUT);
lcd.begin(16,2); //16 by 2 character display
}

void loop()
{
delay(1000); //wait a sec (recommended for DHT11)
sensor.read11(greenPin);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Humidity = ");
lcd.print(sensor.humidity);
lcd.setCursor(0,1);
lcd.print("Temp = ");
lcd.print(sensor.temperature);
x=sensor.temperature;
y=sensor.humidity;
if( x > 25 )
{digitalWrite(fan,LOW);//connected with relay shield
}
if( y < 85)
{digitalWrite(pump,LOW);//connected with relay shield
}

}
//Note: Whether used LOW or HIGH the relay does not respond!!!

In future, please use code tags (</>) to make your codes looking like this:

#include <LiquidCrystal.h>
#include <dht.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int greenPin = A0;
dht sensor;
int fan = 9;
int pump = 8;
float x, y;

void setup()
{
  pinMode(pump, OUTPUT);
  pinMode(fan, OUTPUT);
  lcd.begin(16, 2); //16 by 2 character display
}

void loop()
{
  delay(1000); //wait a sec (recommended for DHT11)
  sensor.read11(greenPin);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Humidity = ");
  lcd.print(sensor.humidity);
  lcd.setCursor(0, 1);
  lcd.print("Temp = ");
  lcd.print(sensor.temperature);
  x = sensor.temperature;
  y = sensor.humidity;
  
  if ( x > 25  )
  { 
    digitalWrite(fan, LOW); //connected with relay shield
  }

  if ( y < 85)
  { 
    digitalWrite(pump, LOW); //connected with relay shield
  }
}

OK i will do :roll_eyes: thanks :wink:

Is your sensor working, and is it showing reasonable values for Temp and Humidity? If yes, try by bringing the following changes in your program:

  if ( x > 25.0  )
  { 
    digitalWrite(fan, LOW); //connected with relay shield
  }

  if ( y < 85.0)
  { 
    digitalWrite(pump, LOW); //connected with relay shield
  }

i will try it soon
When I return to home :slight_smile:
thank you very much

Also, try the following codes (few lines are added for diagnostic purposes and slightly modified to fit with my setup; change them back to fit with your setup) which work well in my MEGA Platform. The fan and pump have been simulated using L (on-board LED of MEGA) and extra LED connected at DPin-8.

#include <LiquidCrystal.h>
#include <dht.h>

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);//12, 11, 5, 4, 3, 2);
const int greenPin = 10;//A0;
dht sensor;
int fan = 13;  //modified to include onboard L of MEGA
int pump = 8;
float x, y;

void setup()
{
  Serial.begin(9600);
  pinMode(pump, OUTPUT);
  digitalWrite(pump, HIGH); //initially HIGH 
  pinMode(fan, OUTPUT);
  lcd.begin(20, 4);//(16, 2); //16 by 2 character display
  digitalWrite(fan, HIGH);   //initially HIGH
}

void loop()
{
  delay(1000); //wait a sec (recommended for DHT11)
  sensor.read11(greenPin);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Humidity = ");
  lcd.print(sensor.humidity);
  Serial.println(sensor.humidity);//added
  lcd.setCursor(0, 1);
  lcd.print("Temp = ");
  lcd.print(sensor.temperature);
  Serial.println(sensor.temperature);//added
  x = sensor.temperature;
  y = sensor.humidity;

  if ( x > 32.0  )   //modified to simulate temp
  {
    digitalWrite(fan, LOW); //connected with relay shield
  }

  if ( y < 85.0)
  {
    digitalWrite(pump, LOW); //connected with relay shield
  }
}

great 8)