Raspberry Pi SHT25 Humidity & Temperature Sensor Java Tutorial

by Dcube Tech Ventures in Circuits > Raspberry Pi

56 Views, 0 Favorites, 0 Comments

Raspberry Pi SHT25 Humidity & Temperature Sensor Java Tutorial

SHT25_connctn.png

SHT25 I2C Humidity and Temperature Sensor ±1.8%RH ±0.2°C I2C Mini Module. The SHT25 high-accuracy humidity and temperature sensor has become an industry standard in terms of form factor and intelligence, providing calibrated, linearised sensor signals in digital, I2C format. Here is the demonstration with a Java code using Raspberry Pi.

What You Need..!

SHT25_I2CS.png
TOUTPI2_C_2.png

1. Raspberry Pi

2. SHT25

3. I²C Cable

4. I²C Shield for Raspberry Pi

5. Ethernet Cable

Connections

SHT25_I2CS.png
TOUTPI2_C_2.png
Screen Shot 2016-03-25 at 6.44.43 pm.png
SHT25_connctn.png

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 SHT25 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 below.

Code

Raspberry Pi SHT25 Humidity & Temperature Sensor Java Tutorial

The python code for SHT25 can be downloaded from our github repository- Dcube Store

Here is the link for the same :

https://github.com/DcubeTechVentures/SHT25/tree/master/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.

// SHT25

import com.pi4j.io.i2c.I2CBus;

import com.pi4j.io.i2c.I2CDevice;

import com.pi4j.io.i2c.I2CFactory;

import java.io.IOException;

public class SHT25

{

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

{

// Create I2C bus

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

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

I2CDevice device = Bus.getDevice(0x40);

// Send temprature measurement command, NO HOLD master

device.write((byte)0xF3);

Thread.sleep(500);

// Read 2 bytes of data

// temp msb, temp lsb

byte[] data = new byte[2];

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;

// Send humidity measurement command, NO HOLD master

device.write((byte)0xF5);

Thread.sleep(500);

// Read 2 bytes of data

// humidity msb, humidity lsb

device.read(data, 0, 2);

// Convert the data

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

// 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);

}

}

Applications

SHT25 temperature and relative humidity sensor has various industrial applications like temperature monitoring, computer peripheral thermal protection and so on..