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

About: We are a group of makers. We work in IoT, IOS app, android app, embedded design, sensor design, raspberry pi, arduino, beaglebone, particle electron, particle photon, Bluetooth.

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 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 it's programming in the python. The python code for HDC1000 can be downloaded from our GitHub community that is Dcube Store.

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:

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

<p>import smbus</p><p>import time</p><p># Get I2C bus</p><p>bus = smbus.SMBus(1)</p><p># HDC1000 address, 0x40(64)</p><p># Select configuration register, 0x02(02)</p><p>#		0x30(48)	Temperature, Humidity enabled, Resolultion = 14-bits, Heater on</p><p>bus.write_byte_data(0x40, 0x02, 0x30)</p><p># HDC1000 address, 0x40(64)</p><p># Send temp measurement command, 0x00(00)</p><p>bus.write_byte(0x40, 0x00)</p><p>time.sleep(0.5)</p><p># HDC1000 address, 0x40(64)</p><p># Read data back, 2 bytes</p><p># temp MSB, temp LSB</p><p>data0 = bus.read_byte(0x40)</p><p>data1 = bus.read_byte(0x40)
# Convert the data</p><p>temp = (data0 * 256) + data1</p><p>cTemp = (temp / 65536.0) * 165.0 - 40</p><p>fTemp = cTemp * 1.8 + 32</p><p># HDC1000 address, 0x40(64)</p><p># Send humidity measurement command, 0x01(01)</p><p>bus.write_byte(0x40, 0x01)</p><p>time.sleep(0.5)</p><p># HDC1000 address, 0x40(64)</p><p># Read data back, 2 bytes</p><p># humidity MSB, humidity LSB</p><p>data0 = bus.read_byte(0x40)</p><p>data1 = bus.read_byte(0x40)</p><p># Convert the data</p><p>humidity = (data0 * 256) + data1</p><p>humidity = (humidity / 65536.0) * 100.0</p><p># Output data to screen</p><p>print "Relative Humidity : %.2f %%" %humidity</p><p>print "Temperature in Celsius : %.2f C" %cTemp</p><p>print "Temperature in Fahrenheit : %.2f F" %fTemp</p>

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

<p>import smbus</p><p>import time</p>

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

$> python 
gt; python

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.