Why does only 1 sensor output meaningful data

I am currently trying to read data from three separate DHT11 sensors; however, I can only get 1 sensor to work. I think the other sensors are either not registering or being overwritten. This is the code:


dht DHT;
dht DHT2;
dht DHT3;


#define DHT11_PIN 5

#define DHT11_PIN 6
#define DHT11_PIN 7


void setup(){
  Serial.begin(9600);
}

void loop(){
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("DHT Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("DHT Humidity = ");
  Serial.println(DHT.humidity);

  chk = DHT2.read11(DHT11_PIN);
  Serial.print("DHT 2 Temperature = ");
  Serial.println(DHT2.temperature);
  Serial.print("DHt 2 Humidity = ");
  Serial.println(DHT2.humidity);

  chk = DHT3.read11(DHT11_PIN);
  Serial.print("DHT 3 Temperature = ");
  Serial.println(DHT3.temperature);
  Serial.print("DHT 3 Humidity = ");
  Serial.println(DHT3.humidity);
  delay(5000);
}

How did you wire the sensors to the Arduino?

Do these three lines cause the compiler to complain about redefinition?
DHT11_PIN ends up being 7. I suspect that you need three different pin names.

#define DHT11_PIN 5

#define DHT11_PIN 6
#define DHT11_PIN 7
2 Likes

Yes, it does complain about redefinition. I wired the signal nodes of the sensors to pin 5, 6, and 7.

One obvious fix might be to define the pin names as DHT11_PIN5, DHT11_PIN6, etc.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.