Hello. I am trying to use an arduino to control two DHT11 (temp. and humidity) sensors with the serial monitor. The problem is, the first sensor displays all the data correctly, however the second sensor does not work. It displays the following:
Temp1: 29.00
Temp2: 0.00
Humidity1: 95.00
Humidity2: 0.00
Here is the code:
#include <dht.h>
dht DHT;
dht DHT2;
#define DHT11_PIN 7
#define DHT11_PIN2 9
void setup(){
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temp1: ");
Serial.println(DHT.temperature);
Serial.print("Temp2: ");
Serial.println(DHT2.temperature);
Serial.print("Humidity: ");
Serial.println (DHT.humidity);
Serial.print("Humidity2: ");
Serial.println(DHT2.humidity);
delay(3000);
Any help would be appreciated. Thanks!
You don't appear to be reading the second sensor.
Hi,
try this code:
#include <dht.h>
dht DHT;
dht DHT2;
#define DHT11_PIN 7
#define DHT11_PIN2 9
//-------------------------------------------------
void setup() {
Serial.begin(9600);
}
//-------------------------------------------------
void loop() {
// put your main code here, to run repeatedly:
int chk = DHT.read11(DHT11_PIN);
int chk2 = DHT2.read11(DHT11_PIN2);
Serial.print("Temp1: ");
Serial.println(DHT.temperature);
Serial.print("Temp2: ");
Serial.println(DHT2.temperature);
Serial.print("Humidity: ");
Serial.println (DHT.humidity);
Serial.print("Humidity2: ");
Serial.println(DHT2.humidity);
delay(3000);
}
Hi ruilviana,
Thanks for the code. It works fine.
Kind regards,
Arduinomaker1897
Do you understand what was wrong with your code ?
Hello UkHeliBob.
It's been a while, but now, after checking it, I see the problem:
In the code, I didn't gave the command to read the second sensor.
Sorry for the late reply,
arduinomaker1897
system
Closed
June 25, 2023, 3:40pm
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.