Raspberry Pi - SI7021 Humidiy & Temperature Sensor Python Tutorial

by Dcube Tech Ventures in Circuits > Electronics

49 Views, 0 Favorites, 0 Comments

Raspberry Pi - SI7021 Humidiy & Temperature Sensor Python Tutorial

Raspberry Pi - SI7021 Humidity & Temperature  Python Sensor Tutorial

SI7021 is a humidity and temperature sensor which can operate on I2C communication protocol. It has a monolithic CMOS IC integrating humidity and temperature sensor elements, an analog-to-digital converter etc. Incorporated with highly advanced signal processing elements and callibration data feature this sensor forms one of the most efficient device to measure humidity and temperature. Here is its demonstration with raspberry pi using python code.

What You Need..!!

SI7021.jpg
pi_1.jpg

Connections:

SI7021.jpg
pi_1.jpg
sensor.jpg
complete_connection.jpg

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 SI7021 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.

Code:

complete_connection.jpg

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

Here is the link for the same :

https://github.com/DcubeTechVentures/SI7021...

We have used SMBus library for python code, the steps to install SMBus on 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.

# SI7021

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

import smbus

import time

# Get I2C bus

bus = smbus.SMBus(1)

# SI7021 address, 0x40(64)

# 0xF5(245) Select Relative Humidity NO HOLD master mode

bus.write_byte(0x40, 0xF5)

time.sleep(0.3)

# SI7021 address, 0x40(64)

# Read data back, 2 bytes, Humidity MSB first

data0 = bus.read_byte(0x40)

data1 = bus.read_byte(0x40)

# Convert the data

humidity = ((data0 * 256 + data1) * 125 / 65536.0) - 6

time.sleep(0.3)

# SI7021 address, 0x40(64)

# 0xF3(243) Select temperature NO HOLD master mode

bus.write_byte(0x40, 0xF3)

time.sleep(0.3)

# SI7021 address, 0x40(64)

# Read data back, 2 bytes, Temperature MSB first

data0 = bus.read_byte(0x40)

data1 = bus.read_byte(0x40)

# Convert the data

cTemp = ((data0 * 256 + data1) * 175.72 / 65536.0) - 46.85

fTemp = cTemp * 1.8 + 32

# Output data to screen

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

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

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

Applications:

SI7021 is a highly efficient and reliable sensor that can be incorporated in indoor weather stations that can maintain the optimum indoor environment in terms of humidity and temperature suited for human body.It forms an integral part in automotive climate control and defogging systems. It can also be employed in mobile phones and tablets.