The DHT22 can be purchased pretty much everywhere from SparkFun (~$10 USD) to eBay (~$3 CDN). The DHT11 is even more pervasive and inexpensive, at less than $1.50 CDN on eBay.
According to Adafruit, the differences between the devices are:
DHT11
20-80% humidity readings with 5% accuracy
0-50°C temperature readings with 2°C accuracy
1Hz sampling rate (once every second)
smaller than DHT22
DHT22
0-100% humidity readings with 2-5% accuracy
-40-125°C temperature readings with 0.5°C accuracy
0.5Hz sampling rate (once every 2 second)
bigger than DHT11
Deciding between them is up to you. For almost everything 2°C is a good accuracy, as are the temperature and humidity ranges of the DHT11. If you want a less power hungry sensor, the DHT22 is a better all-round device. From now on, I'm just going to refer to them both as DHTXX.
Arduino
I will update this post in the future if I decide to use this sensor with anything other than Arduino, but for now that's what I'm working on.
Wiring
These little sensors have four pins, but you use only three of them (see figure).
The pins are labelled 1-4 with the grating cover facing you. Pin 1 (called VCC) is the power pin, connected to either your 5V or 3.3V power supply. Even if you are running other things off of 5V (LCD screen, motor, etc.), you can connect this to the 3.3V pin. The reason for going lower voltage is two fold. One, the device consumes less power in general (less drain on battery). In fact, if you're using a 9V battery as your power supply, this sensor will then keep going long after things requiring 5V power stop working. Two, the sensor sends a voltage proportional to the temperature or humidity as data (i.e. 0V for 20% humidity, 5V for 80% humidity in the DHT11). Say the sensor can give you a range of 1024 values. How it would do this is to break the 5V up into 1024 values, and these would correspond to readings. Theoretically if you broke 3.3V into 1024 values, the sensor could read smaller changes in readings. This is a general rule for most sensors, but for all intents and purposes, it really doesn't matter which you choose. Keep in mind, that the error is way more than any sensitivity you'll gain, but it's nice to know how to do it.
As you can see above, the wiring is extremely simple. If anyone is interested, I can show you my setup with a 16x2 LCD display as well.
Coding
To start with, you'll have to download the DHTXX library. Here is a link to the one I used from Adafruit's github page or just click here for the direct download (if you trust me ;) ). Download this file to anywhere, and uncompress it if it is in a zip file. Now open the Arduino IDE and go to sketch > import library > add library... select the folder you just uncompressed, and click ok. If you get an error, just change any "-" in the folder name to "_". This is a common github problem, where Arduino IDE doesn't like the automatically generated "-" from github downloads.
Close the Arduino IDE and re-open it (a good practice). Here is my code:
I calibrated my temperature by monitoring the temperature output of the DHTxx with the glass thermometer right beside it. I noticed that my sensor was consistently ~2 degrees C off from the glass thermometer, so I changed my tCorrection value to 2. Each sensor will have a different value, so keep it at 0 until you work it out.
If there are any questions or comments, leave them below and I will try to answer them to the best of my ability!
No comments:
Post a Comment