Go Down

Topic: 2 DHT22 sensors. (Read 486 times) previous topic - next topic

noobcoder22

Mar 19, 2018, 11:47 am Last Edit: Mar 19, 2018, 12:07 pm by noobcoder22
Good day everyone,
recently ive been struggling to use 2 DHT22 at the same time. but only 1 DHT22 sensor is sending data and the other one does not. any suggestions?

Here is the image of the serial monitor

https://prnt.sc/it7mfk

Here are the codes

Code: [Select]
//Libraries
#include <DHT.h>
#define DHTPIN1 3
#define DHTPIN2 4


#define DHTTYPE1 DHT22 // DHT 22 (AM2302)
#define DHTTYPE2 DHT22 // DHT 22 (AM2302)


DHT dht1(DHTPIN1, DHTTYPE1);
DHT dht2(DHTPIN2, DHTTYPE1);



//Variables
int chk;
float hum1;  //Stores humidity value
float temp1; //Stores temperature value
float hum2;  //Stores humidity value
float temp2; //Stores temperature value
void setup()
{
Serial.begin(9600);
dht1.begin();
dht2.begin();
}

void loop()
{
delay(2000);
//Read data and store it to variables hum and temp
hum1 = dht1.readHumidity();
temp1= dht1.readTemperature();
hum2 = dht2.readHumidity();
temp2= dht2.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity1: ");
Serial.print(hum1);
Serial.print(" %, Temp1: ");
Serial.print(temp1);
Serial.println(" Celsius");
Serial.print("Humidity2: ");
Serial.print(hum2);
Serial.print(" %, Temp2: ");
Serial.print(temp2);
Serial.println(" Celsius");
delay(10000); //Delay 2 sec.
}

robtillaart

#1
Mar 19, 2018, 11:52 am Last Edit: Mar 19, 2018, 11:53 am by robtillaart
Welcome on the forum,


tip 1: use code tags  (you can update your post)

tip 2: try to swap the sensors, if the other now works the sensor is not broken.

tip 3: check your wiring

tip 4: post the output of the sketch.

tip 5: do you have pull up resistors on the datapin (4K7 ohm)

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

noobcoder22

how do i use a pull up resistor in parallel with 5v and data or in series with data? thanks for the reply

robtillaart

- https://www.iot-programmer.com/images/stories/Core/Hardware/Microbit/DHT22/DHT22circuit.jpg
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

noobcoder22

http://prntscr.com/it8n1e

managed to do the pull up resistor but still the second DHT22 sensor did not send any data. i think theres something wrong with the codes bu i cant tell.

also the wiring is okay since both DHT22 works well one at a time but when it comes together it does not.

falexandru

I have a circuitry of one DHT22, one BMP280 (I2C) and one TEMT6000 + 1602 on I2C. Clone Arduino  Nano.

The most stable reading is from the DHT22 (20 minutes, difference in readings over time is bellow 1C). On 5V, 4K7 Resistor data to VCC.

From what I read, some recommends 5V instead of 3V3, for a more accurate and stable reading.

+++

You may comment the lines of each sensor and see which is the one not sending data.

Then, check the wires of the one you identified as not working.


Tip1: use permanent markers to stamp each sensor (say 1 and 2).

Tip2: some jumpers makes "bad jokes" namely they allow sliding of the black plastic tube over metallic core, which protrude only a little in the breadboard, so not actually getting to the contacts in the breadboard.

So, dont believe your eyes! :-)) Just pull and plug all jumpers of the line of the DHT22 which you find as not sending data.

noobcoder22

thank you very much guys. just found out one of my jumper wires gut busted

Go Up