Raspberry Pi - SI7006-A20 Humidity & Temperature Sensor Java Tutorial

by Dcube Tech Ventures in Circuits > Electronics

8 Views, 0 Favorites, 0 Comments

Raspberry Pi - SI7006-A20 Humidity & Temperature Sensor Java Tutorial

Raspberry Pi - SI7006-A20 Humidity & Temperature  Java Sensor Tutorial

SI7006-A20 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 java code.

What You Need..!!

SI7006.jpg
pi_1.jpg

1. Raspberry Pi

2. SI7006-A20

3. I²C Cable

4. I²C Shield for Raspberry Pi

5. Ethernet Cable

Connections:

SI7006.jpg
pi_1.jpg
sensor.jpg
complete_connection.jpg

Take a 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 SI7006-A20 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 java code for SI7006-A20 can be downloaded from our github repository-DCUBE Store.

Here is the link.

https://github.com/DcubeTechVentures/SI7006-A20/blob/master/java/SI7006_A20.java

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

http://pi4j.com/install.html

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.

// SI7006-A20

// This code is designed to work with the SI7006-A20_I2CS I2C Mini Module .

import com.pi4j.io.i2c.I2CBus;

import com.pi4j.io.i2c.I2CDevice;

import com.pi4j.io.i2c.I2CFactory;

import java.io.IOException;

public class SI7006_A20

{

public static void main(String args[]) throws Exception

{

// Create I2C bus

I2CBus Bus = I2CFactory.getInstance(I2CBus.BUS_1);

// Get I2C device, SI7006_A20 I2C address is 0x40(64)

I2CDevice device = Bus.getDevice(0x40);

// Send humidity measurement command, NO HOLD MASTER

device.write((byte)0xF5);

Thread.sleep(500);

// Read 2 bytes of humidity data

// humidity msb, humidity lsb

byte[] data = new byte[2];

device.read(data, 0, 2);

// Convert the data

double humidity = (((((data[0] & 0xFF) * 256.0) + (data[1] & 0xFF)) * 125.0) / 65536.0) - 6;

// Send temperature measurement command, NO HOLD MASTER

device.write((byte)0xF3);

Thread.sleep(500);

// Read 2 bytes of temperature data

// temp msb, temp lsb

device.read(data, 0, 2);

// Convert the data

double cTemp = (((((data[0] & 0xFF) * 256) + (data[1] & 0xFF)) * 175.72) / 65536.0) - 46.85;

double fTemp = cTemp * 1.8 + 32;

// Output data to screen

System.out.printf("Relative Humidity : %.2f %%RH %n", humidity);

System.out.printf("Temperature in Celsius : %.2f C %n", cTemp);

System.out.printf("Temperature in Fahrenheit : %.2f F %n", fTemp);

}

}

Applications:

SI7006-A20 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.