Friday, January 25, 2013

DHT11 temperature sensors

=== This log post is in raw form. This is not the final presentation, but making information available is more important than making it pretty. ===

Today I received 4 DHT11 temperature sensors. They were a deal, but it turns out they're all labeled in Chinese.


Google searches bring us to the Adafruit page for the device. Under the downloads tab, you'll find the manual in Chinese. Fortunately, Google Translate gives us something passable. Even better, there's a similar guide in English linked from Adafruit.


The guide lists various specifications for accuracy and operational speed. It mentions a 1 second delay several times. Near the bottom is the pinout. While the device has 4 pins, only 3 of them are used; one is merely there to physically connect the device to the mounting board. This is good because those pins are thin and flimsy. I bent one putting it into the solderless board.

Pin Name
Note
1
VDD
Powered 3-5.5VDC
2
DATA
Serial data, single-bus
3
NC
Empty feet vacant
4
GND
Ground, power supply negative

But this is backwards, if you look at the label. From the above image, the VDD goes on the rightmost pin, GND on the left, with the DATA next to the VDD. The code sample that worked for me specifies the DATA pin should connect to the Android's analog A0 pin.

Elsewhere the guide mentions a single-pin bus, so I'm assuming it works much the same as the Ping ultrasonic distance sensor, using the same pin as input and output.

So how to get it working on the Arduino? 

First, you need to make a DHT11 library. You'll need to make a new folder in your /arduino/libraries/ folder. Then you'll need to fill it with dht11.h and dht11.cpp, which tells the Arduno's C++ compiler how to handle the commands for the DHT11. I got the files from the bottom of this page -- you actually make a text file, rename it, then copy the code from the page, and paste it in the renamed text file. (You might be able to click "get code" at the bottom of each section, but all that did for me was display the code in my browser).

Once you've got the libraries in place and have restarted the Arduino IDE, you should be ready for code. While the code for the libraries seems to work great, the example code on the same page provided a repeating pattern of letters and numbers and weird shapes. Through some digging, I was able to find another source. The first section of code on this page, however, provided a nice, repeating output:


Current humdity = 38.0%  temperature = 21.0C


So I think we have a keeper. I'm planning on combining this with the xbee wifi device, to make a networked wireless device you put in your fridge. I want it to host a webpage, showing temperature statistics for your refrigerator. I know it's not a moving robot, but robots are about automation. Maybe I can kickstarter this!








No comments:

Post a Comment