Introduction: Raspberry Pi - HIH6130 I2C Humidity & Temperature Sensor Python Tutorial

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.

HIH6130 is a humidity and temperature sensor with digital output. These sensors provide an accuracy level of ±4% RH. With industry-leading long-term stability, true temperature-compensated digital I2C, Industry-leading reliability, Energy efficiency and Ultra-small package size and options. Here is its demonstration with raspberry pi using python code.

Step 1: What You Need..!!

Step 2: Connections:

Take an I2C shield for raspberry pi and gently push it over the gpio pins of raspberry pi.

Then connect the one end of I2C cable to HIH6130 sensor and the other end to the I2C shield.

Also connect the Ethernet cable to the pi or you can use a WiFi module.

Connections are shown in the picture above.

Step 3: Code:

The python code for HIH6130 can be downloaded from our GitHub repository- Dcube Store.

Here is the link for the same :

https://github.com/DcubeTechVentures/HIH6130

We have used SMBus library for python code, the steps to install SMBus on the raspberry pi is described here:

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

You can also copy the code from here, it is given as follows:

# Distributed with a free-will license.

# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.

# HIH6130

# This code is designed to work with the HIH6130_I2CS I2C Mini Module available in Dcube Store.

import smbus

import time

# Get I2C bus

bus = smbus.SMBus(1)

# HIH6130 address, 0x27(39)

# Read data back from 0x00(00), 4 bytes

# humidity MSB, humidity LSB, temp MSB, temp LSB

data = bus.read_i2c_block_data(0x27, 0x00, 4)

# Convert the data to 14-bits

humidity = ((((data[0] & 0x3F) * 256) + data[1]) * 100.0) / 16383.0

temp = (((data[2] & 0xFF) * 256) + (data[3] & 0xFC)) / 4

cTemp = (temp / 16384.0) * 165.0 - 40.0

fTemp = cTemp * 1.8 + 32

# Output data to screen

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

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

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

Step 4: Applications:

HIH6130 can be used to provide precise relative humidity and temperature measurement in air conditioners, enthalpy sensing, thermostats, humidifiers/de-humidifiers, and humidistats to maintain occupant comfort. It can also be employed in air compressors, weather stations and telecom cabinets.