Raspberry Pi - Humidity / Temperature Data Logger / Grapher
Using DHT22 Sensor

revised 02-26-13  d. bodnar


I have been working with the Raspberry Pi for a few months and have had a great time experimenting.  See my other page of notes on the Pi here and the notes on using the Pi as a temperature logger here.

My latest project is to use the Pi as a data logger that will read humidity and temperature data from one or more DHT22 temperature sensors.  This data will be recorded to a file and periodically graphed and posted on the Internet.

GNUPlot will be used to produce the graphs.

Sample graphs (may be up-to-date or not depending on what I am doing to them) can be seen here.


Initial Installation
Much of the work that I have done is based on the excellent tutorial provided by the folks at Adafruit.

Note that you may have to do an update and an upgrade to use "git"  or may need to install "git"

The DHT22 sensors are inexpensive and can be used to gather both humidity and temperature.  These devices have four pins.  The leftmost pin connects to + 3.3 volts, the next pin is data and the rightmost pin goes to ground.  The third pin is not used.  A 10K resistor needs to be connected between pins 1 and 2 to pull the data line high.

These sensors cannot be wired in parallel as the DS18B20s can.  Each sensor must have its own 3 wire cable (+ 3.3 volts, data and ground) and each data line must connect to its own GPIO pin.

Python is too slow to read the sensors directly.  Fortunately an executable "C" program is available that takes care of reading the sensors.  It is available for download here: http://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/software-install

My installation did not contain the "git" file that is used in this link but a quick   sudo apt-git install git   took care of the issue. 

Also, the top two lines of the installation must be combined so that it reads:

git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git


Notes on the following were found here:  http://www.stuffaboutcode.com/2012/06/raspberry-pi-run-program-at-start-up.html
To get the program to auto-start after a power failure put this script (called StartHumid.sh) into the /etc/init.d directory

#! /bin/sh
# /etc/init.d/StartHumid.sh

# Provides: noip
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Simple script to start a program at boot
# Description: A simple script from www.stuffaboutcode.com which will start / stop a program a boot / shutdown.

#sudo -i
cd /home/pi
python /home/pi/Humid7.py


once created do the following:

Make script executable
sudo chmod 755 /etc/init.d/StartHumid.sh

Start the program
sudo /etc/init.d/StartHumid.sh start

Stop the program
sudo /etc/init.d/
StartHumid.sh stop

Register script to be run at start-up
To register your script to be run at start-up and shutdown, run the following command:

sudo update-rc.d StartHumid.sh defaults




free web counter