Raspberry Pi and HDC1008 temperature sensor

The HDC1008 is a digital humidity sensor with integrated temperature sensor that provides excellent measurement accuracy at very low power. The device measures humidity based on a novel capacitive sensor. The humidity and temperature sensors are factory calibrated.

hdc1008

The sensing element of the HDC1008 is placed on the bottom part of the device, which makes the HDC1008 more robust against dirt, dust, and other environmental contaminants. The HDC1000 is functional within the full –40°C to +125°C temperature range.

Key Features

  • Relative Humidity (RH) Operating Range 0% to 100%
  • 14 Bit Measurement Resolution
  • Relative Humidity Accuracy ±3%
  • Temperature Accuracy ±0.2°C
  • Supply Voltage 3 V to 5 V
  • I2C Interface

Connection

 

pi-and-hdc1008_bb

 

Code

Save the following as HDC1008.py

import smbus
import time
 
# Get I2C bus
bus = smbus.SMBus(1)
 
# HDC1000 address, 0x40
bus.write_byte_data(0x40, 0x02, 0x30)
 
# Send temp measurement command
bus.write_byte(0x40, 0x00)
 
time.sleep(0.5)
 
# Read temp data
data0 = bus.read_byte(0x40)
data1 = bus.read_byte(0x40)
 
# Convert the data
temp = (data0 * 256) + data1
celsTemp = (temp / 65536.0) * 165.0 - 40
fahrTemp = celsTemp * 1.8 + 32
 
# Send humidity measurement command
bus.write_byte(0x40, 0x01)
time.sleep(0.5)
 
# Read humidity data
data0 = bus.read_byte(0x40)
data1 = bus.read_byte(0x40)
 
# Convert the data
humidity = (data0 * 256) + data1
humidity = (humidity / 65536.0) * 100.0
 
# Output data
print "Relative Humidity : %.2f %%" %humidity
print "Temperature in Celsius : %.2f C" %celsTemp
print "Temperature in Fahrenheit : %.2f F" %fahrTemp

Output

Run the following from the command line using sudo python HDC1008.py

hdc1008-output

Links

HDC1008 Temperature Humidity Sensor Breakout Board for Arduino

SHARE
Previous articleRaspberry Pi and BMP180 sensor
Next articleRaspberry Pi and PCF8574 example