I am just getting into Arduino after trying to fix an issue that I had. The main issue that I am running into is pulling values from multiple DHT11s. I am able to pull the value from one sensor fine, however, when I connect multiples (currently using 4), all of the values return the same value, no matter what changes I make to individual sensors. I have attempted to follow several guides that I've seen online, but can't seem to get any of them to work. Any help would be greatly appreciated.!!
I assume the issue is where the floats are defined, but I can't seem to get the code to compile with any changes to this section.
#include <dht.h>
#define dht1 A0
#define dht2 A1
#define dht3 A2
#define dht4 A3
dht DHT;
int fan1 = 4;
int fan2 = 5;
int fan3 = 6;
int fan4 = 7;
void setup()
{
Serial.begin(9600);
delay (500);
Serial.println("DHT11 test!");
pinMode(fan1, OUTPUT);
pinMode(fan2, OUTPUT);
pinMode(fan3, OUTPUT);
pinMode(fan4, OUTPUT);
// pinMode(dht1, INPUT);
}
void loop()
{
DHT.read11(dht1);
DHT.read11(dht2);
DHT.read11(dht3);
DHT.read11(dht4);
float h1 = DHT.humidity;
float t1 = DHT.temperature;
float h2 = DHT.humidity;
float t2 = DHT.temperature;
float h3 = DHT.humidity;
float t3 = DHT.temperature;
float h4 = DHT.humidity;
float t4 = DHT.temperature;
if (isnan(t1) || isnan(h1)) {
Serial.println("Failed to read from DHT #1");
}
else {
Serial.print("Humidity 1: ");
Serial.print(h1);
Serial.print(" %\t");
Serial.print("Temperature 1: ");
Serial.print(t1);
Serial.println(" *C");
}
if (isnan(t2) || isnan(h2)) {
Serial.println("Failed to read from DHT #1");
}
else {
Serial.print("Humidity 2: ");
Serial.print(h2);
Serial.print(" %\t");
Serial.print("Temperature 2: ");
Serial.print(t2);
Serial.println(" *C");
}
if (isnan(t1) || isnan(h1)) {
Serial.println("Failed to read from DHT #1");
}
else {
Serial.print("Humidity 3: ");
Serial.print(h3);
Serial.print(" %\t");
Serial.print("Temperature 3: ");
Serial.print(t3);
Serial.println(" *C");
}
if (isnan(t1) || isnan(h1)) {
Serial.println("Failed to read from DHT #1");
}
else {
Serial.print("Humidity 4: ");
Serial.print(h4);
Serial.print(" %\t");
Serial.print("Temperature 4: ");
Serial.print(t4);
Serial.println(" *C");
}
if(h1 >= 50)
{
analogWrite(fan1,255);
}
else
{
analogWrite(fan1,0);
}
delay(5000);
}