2 rly

Hello;
How to read from 2 defrent humidity sensors and exicute 2 defrent relys in the same time?

this is the code

//Libraries
#include <DHT.h>;

//Constants
#define DHTPIN1 2 // what pin we’re connected to
#define DHTPIN2 3
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht1(DHTPIN1, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
DHT dht2(DHTPIN2, DHTTYPE);

//Variables
int chk;
float hum1; //Stores humidity value
float hum2;
float temp; //Stores temperature value

void setup()
{
Serial.begin(9600);
//dht.begin();
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
dht1.begin();
dht2.begin();
}

void loop()
{
//Read data and store it to variables hum and temp
// delay(240000);
hum1 = dht1.readHumidity();
hum2 = dht2.readHumidity();
temp= dht2.readTemperature();

if(hum1 >= 52){
digitalWrite(8,HIGH);
delay(2000);
digitalWrite(8,LOW);
}else{
digitalWrite(8,LOW);
}
if(hum2 >= 52){
digitalWrite(9,HIGH);
delay(2000);
digitalWrite(9,LOW);
}else{
digitalWrite(9,LOW);
}
//Print temp and humidity values to serial monitor
Serial.print(“Humidity: “);
Serial.print(hum1);
Serial.print(” %, Temp: “);
Serial.print(temp);
Serial.println(” Celsius”);
delay(2000); //Delay 2 sec.

}

look at the Blink Without Delay example in the IDE (File->Examples->02.Digital->BlinkWithoutDelay). It will show you have to get rid of your delay() functions and track elapsed time.

Then, change your code so that you read the sensors and if they are at the correct level, set your relay and record the time. Later, you will check how much time has elapsed and turn off your relay

Hi
I have 2 defrent DHT sensors

I want to excute one rely from one sensor

each sensor excute one rely at the same time

in my programme , the first sensor excute the first rely then the 2nd

how to fix it

Moussa-Guemdani:
how to fix it

See reply #2