I have this DHT22 sensor:
It is a white case on a red board which has DAT, VCC and GND connections. Also to the left side it is labeled as AM2302 DHT22 sensor and on the right side it says 1400C80
In the sketch I am using, it says to Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
Is it necessary and if so will it give data readings, as presently it just gives 00% humidity and 0.0C temperature.
Thanks
Your board has 3 pins, facing the board left to right Ground, VCC and Data. You do not need an external added resistor. If you actually look closely at the board you will see a resistor acting as a pullup between data out and VCC. AM2302 is just another name for the actual sensor.
A link to the sketch or posting the code would help. I have used the same module you have and also the DHT11 modules and they have always worked fine. I have no clue why you are seeing what you are seeing.
Ron
Ok thanks for the reply.
As the sketch is pver 500 lines long, here is a ink to the project with the sketch:
That is lengthy. They reference a DHT 11 and a DHT 11 library. Then I don't see it called again unless I missed it in the maze. I can tell you having used both the DHT 11 and DHT 22 that the correct one needs to be called out in the code. I have never used the library they mentioned for it.
Here is what I suggest you try. Run a quick and simple DHT22 code sample like this one.
/* How to use the DHT-22 sensor with Arduino uno
Temperature and humidity sensor
*/
//Libraries
#include <DHT.h>;
//Constants
#define DHTPIN 7 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
//Variables
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
void setup()
{
Serial.begin(9600);
dht.begin();
}
void loop()
{
delay(2000);
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(10000); //Delay 2 sec.
}
See what you get on the serial monitor. Note they use pin 7 as the data pin. If this runs you know your module is good and the problem is in the code. Obviously for the DHT 22 there is not much wiring involved. I do remember if I defined the DHT Type incorrectly in my code I got bad data but not zeros.
Ron
You do NOT need to use the 10K resistor because it is built in the module.
You may install the incorrect library.
See all about DHT22 sensor
@Ron_Blain
Thanks, I first copied the code / sketch for the DHT22 , but got an error saying 'DHT22' was not declared in this scope. I then scrubbed that sketch and typed it it line by line while checking and double checking.
Arduino: 1.8.8 (Linux), Board: "Arduino/Genuino Uno"
dht22_test:11:17: error: 'DHT22' was not declared in this scope
#define DHTTYPE DHT22
^
/home/rob/sketchbook/dht22_test/dht22_test.ino:13:17: note: in expansion of macro 'DHTTYPE'
DHT dht(DHTPIN, DHTTYPE);
^
/home/rob/sketchbook/dht22_test/dht22_test.ino: In function 'void setup()':
dht22_test:17:7: error: 'class DHT' has no member named 'begin'
dht.begin(); // initialize the sensor
^
/home/rob/sketchbook/dht22_test/dht22_test.ino: In function 'void loop()':
dht22_test:25:21: error: 'class DHT' has no member named 'readHumidity'
float humi = dht.readHumidity();
^
dht22_test:27:21: error: 'class DHT' has no member named 'readTemperature'
float tempC = dht.readTemperature();
^
dht22_test:29:21: error: 'class DHT' has no member named 'readTemperature'
float tempF = dht.readTemperature(true);
^
Multiple libraries were found for "DHT.h"
Used: /home/rob/sketchbook/libraries/DHT
Not used: /home/rob/sketchbook/libraries/arduino-DHT
Not used: /home/rob/sketchbook/libraries/DHT_sensor_library-1.3.2
Not used: /home/rob/sketchbook/libraries/DHT_sensor_library
Using library DHT in folder: /home/rob/sketchbook/libraries/DHT (legacy)
exit status 1
'DHT22' was not declared in this scope
@IoT_hobbyist
Thanks for the information, and I then used or copied the code from the link you gave , but I am still getting the same error as above
I do have the DHT library installed as well as DHTlib and the one by Rob Tillard; AM232X library
Thanks
avalon66:
@IoT_hobbyist
Thanks for the information, and I then used or copied the code from the link you gave , but I am still getting the same error as above
I do have the DHT library installed as well as DHTlib and the one by Rob Tillard; AM232X library
Thanks
Did you install all libraries as instructed in the tutorial?
There are many DHT sensor library. Please install the correct library from Adafruit.
To avoid conflict, please delete all DHT library and install the library from Adafruit.
Ok I have got the DHT22 working now on another Arduino , so it reads data fine now.
I downoaded the sketch again and found that I had to change DHT11 instances to DHT22, and now it reads data just fine.
Thanks
avalon66:
Ok I have got the DHT22 working now on another Arduino , so it reads data fine now.
I downoaded the sketch again and found that I had to change DHT11 instances to DHT22, and now it reads data just fine.
Thanks
Oh yeah, that will do it. Been there and done that but my code ran, just bad numbers. Glad it came together.
Ron