Introduction: Raspberry Pi - HIH6130 I2C Humidity & Temperature Sensor Java Tutorial
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 java 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 java code for HIH6130 can be downloaded from our GitHub repository- Dcube Store
Here is the link for the same :
We have used pi4j library for java code, the steps to install pi4j on raspberry pi is described here:
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.
// This code is designed to work with the HIH6130_I2CS I2C Mini Module available in Dcube Store.
public class HIH6130
public static void main(String args) throws Exception
// Create I2C bus
I2CBus Bus = I2CFactory.getInstance(I2CBus.BUS_1);
// Get I2C device, HIH6130 I2C address is 0x27(39)
I2CDevice device = Bus.getDevice(0x27);
// Read 4 bytes of data
// humidity msb, humidity lsb, temp msb, temp lsb
byte data = new byte;
device.read(0x00, data, 0, 4);
// Convert the data to 14-bits
double humidity = (((data & 0x3F) * 256) + (data & 0xFF)) / 16384.0 * 100.0;
int temp = ((((data & 0xFF) * 256) + (data & 0xFC)) / 4);
double cTemp = (temp / 16384.0) * 165.0 - 40.0;
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 Farhenheit : %.2f F %n", 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.