Beaglebone and DHT12 temperature sensor example in python

In this article we look at another sensor – this time its the DHt12 and we will connect it to our Beaglebone and we will have a python example

The DHt12 is an upgraded version of the classic DHT11 humidity temperature sensor, it is fully downward compatible, more precise and adds an I2C interface.

Features:

compact size
low power consumption
low voltage operation
Standard I2C and 1-wire interface.

Sensing range
Temperature: -20 ~ +60 C
Humidity: 20-95 RH
Humidity:
Resolution: 0.1%RH
Repeat: -+ 1%RH
Precision 25C @ -+5RH
Temperature:
Resolution: 0.1C
Repeat: -+0.2C
Precision: 25C @ -+0.5C
Power: DC 2.7-5.5V
Normal current 1mA
Standby current 60uA
Sample cycle: > 2 seconds

Pin interface: 1. VDD 2. SDA 3. GND 4. SCL (connect to GND when use as 1-wire)

 

Parts List

Name Link
Beaglebone BeagleBone Black TI AM335x Cortex-A8 development BB-Black Rev.C
DHT12 DHT12 Module Digital Temperature and Humidity Sensor
connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Schematic/Connection

Beaglebone Module
3.3v – P9.3 Vcc
Gnd – P9.1 Gnd
SDA – P9.20 SDA
SCL – P9.19 SCL
beaglebone and DHT12 output
beaglebone and DHT12 output

 

Code

[codesyntax lang=”python”]

import smbus

bus = smbus.SMBus(2)

data = bus.read_i2c_block_data(0x5C,0x00, 5)

if (data[0] + data[1] + data[2] + data[3] == data[4]):
    print "checksum is correct"
else:
    print "checksum is incorrect"

print "Humidity = " + str(data[0]) + "." + str(data[1]) + "%"
print "Temperature : " + str(data[2]) + "." + str(data[3]) + "C"

[/codesyntax]

 

Output

Run the above code. You should see something like this

debian@beaglebone:/var/lib/cloud9/iain$ python DHT12.py
checksum is correct
Humidity = 46.3%
Temperature : 19.8C
debian@beaglebone:/var/lib/cloud9/iain$ python DHT12.py
checksum is correct
Humidity = 55.8%
Temperature : 19.9C
debian@beaglebone:/var/lib/cloud9/iain$ python DHT12.py
checksum is correct
Humidity = 67.2%
Temperature : 20.9C
debian@beaglebone:/var/lib/cloud9/iain$ python DHT12.py
checksum is correct
Humidity = 71.4%
Temperature : 23.5C

Link

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here