Introduction: Measurement of Temperature and Humidity Using HDC1000 and Raspberry Pi

The HDC1000 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. It is functional within the full -40°C to +125°C temperature range.

In this tutorial the interfacing of the HDC1000 sensor module with raspberry pi is demonstrated and its programming using python language has also been illustrated. To read the temperature and humidity values, we have used raspberry pi with an I2C adapter.This I2C adapter makes the connection to the sensor module easy and more reliable.

Step 1: Hardware Required:

The materials that we need for accomplishing our goal includes the following hardware components:

1. HDC1000

2. Raspberry Pi

3. I2C Cable

4. I2C Shield for raspberry pi

5. Ethernet Cable

Step 2: Hardware Hookup:

The hardware hookup section basically explains the wiring connections required between the sensor and the raspberry pi. Ensuring correct connections is the basic necessity while working on any system for the desired output. So, the requisite connections are as follows:

The HDC1000 will work over I2C . Here is the example wiring diagram, demonstrating how to wire up each interface of the sensor.

Out-of-the-box, the board is configured for an I2C interface, as such we recommend using this hookup if you’re otherwise agnostic.

All you need is four wires! Only four connections are required Vcc, Gnd, SCL and SDA pins and these are connected with the help of I2C cable.

These connections are demonstrated in the pictures above.

Step 3: Code for Temperature and Humidity Measurement:

The advantage of using raspberry pi is, that is provides you the flexibility of the programming language in which you want to program the board in order to interface the sensor with it. Harnessing this advantage of this board, we are demonstrating here its programming in the python. The python code for HDC1000 can be downloaded from our github community that is Control Everything Community.

As well as for the ease of the users, we are explaining the code here also:

As the first step of coding you need to download the smbus library in case of python, because this library supports the functions used in the code. So, to download the library you can visit the following link:

https://pypi.python.org/pypi/smbus-cffi/0.5.1

You can copy the working python code for this sensor from here also:

import smbus

import time

# Get I2C bus

bus = smbus.SMBus(1)

# HDC1000 address, 0x40(64)

# Select configuration register, 0x02(02)

# 0x30(48) Temperature, Humidity enabled, Resolultion = 14-bits, Heater on

bus.write_byte_data(0x40, 0x02, 0x30)

# HDC1000 address, 0x40(64)

# Send temp measurement command, 0x00(00)

bus.write_byte(0x40, 0x00)

time.sleep(0.5)

# HDC1000 address, 0x40(64)

# Read data back, 2 bytes

# temp MSB, temp LSB

data0 = bus.read_byte(0x40)

data1 = bus.read_byte(0x40) # Convert the data

temp = (data0 * 256) + data1

cTemp = (temp / 65536.0) * 165.0 - 40

fTemp = cTemp * 1.8 + 32

# HDC1000 address, 0x40(64)

# Send humidity measurement command, 0x01(01)

bus.write_byte(0x40, 0x01)

time.sleep(0.5)

# HDC1000 address, 0x40(64)

# Read data back, 2 bytes

# humidity MSB, humidity LSB

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 to screen

print "Relative Humidity : %.2f %%" %humidity

print "Temperature in Celsius : %.2f C" %cTemp

print "Temperature in Fahrenheit : %.2f F" %fTemp

The part of code mentioned below includes the libraries required for the correct execution of the python codes.

import smbus

import time

The code can be executed by typing the below mentioned command in the command prompt.

$> python HDC1000.py 

The output of the sensor is also shown in the picture above for the reference of the user.

Step 4: Applications:

HDC1000 can be employed in heating, ventilation and air conditioning (HVAC), Smart Thermostats and Room Monitors. This sensor also finds its application in Printers, Handheld Meters,Medical Devices,Cargo Shipping as well as Automotive Windshield Defog.

Comments