Home Code DHT12 temperature sensor and Raspberry Pi example

DHT12 temperature sensor and Raspberry Pi example

by shedboy71

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.


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

Sensing range
Temperature: -20 ~ +60 C
Humidity: 20-95 RH
Resolution: 0.1%RH
Repeat: -+ 1%RH
Precision 25C @ -+5RH
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)


This shows how to connect the DHT12 to a Raspberry Pi






[codesyntax lang=”python”]

import smbus

DEVICE = 0x5C #device I2C address
bus = smbus.SMBus(1)

def readdata(addr=DEVICE):

#read 5 bytes of data from the device address (0x05C) starting from an offset of zero
data = bus.read_i2c_block_data(addr,0x00, 5)

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

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

if __name__==”__main__”:






Under $1 for one of these sensors

1pcs DHT-12 DHT12 sensor Digital output Temperature and Humidity Sensor high quality

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More