Raspberry Pi HDC1000 Temperature Sensor Java Tutorial
by Dcube Tech Ventures in Circuits > Electronics
11 Views, 0 Favorites, 0 Comments
Raspberry Pi HDC1000 Temperature Sensor Java Tutorial
The HDC1000 is a digital humidity sensor with integrated temperature sensor that provides excellent measurement accuracy at very low power. The device measures humidity based on a novel capacitive sensor. The humidity and temperature sensors are factory calibrated. It is functional within the full -40°C to +125°C temperature range. Here is its demonstration with Raspberry Pi using java code.
What You Need..!!
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 HDC1000 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:
The python code for HDC1000 can be downloaded from our GitHub repository- Dcube Store.
Here is the link for the same :
https://github.com/DcubeTechVentures/HDC1000...
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.
// HDC1000
// This code is designed to work with the HDC1000_I2CS I2C Mini Module available in Dcube Store.
import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CDevice;
import com.pi4j.io.i2c.I2CFactory;
import java.io.IOException;
public class HDC1000
{
public static void main(String args[]) throws Exception
{
// Create I2C bus
I2CBus Bus = I2CFactory.getInstance(I2CBus.BUS_1);
// Get I2C device, HDC1000 I2C address is 0x40(64)
I2CDevice device = Bus.getDevice(0x40);
Thread.sleep(500);
// Select configuration register
// Temperature, humidity enabled, resolultion = 14-bits, heater on
device.write(0x02, (byte)0x30);
Thread.sleep(100);
// Send temp measurement command
device.write((byte)0x00);
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
int temp = ((data[0] & 0xFF) * 256 + (data[1] & 0xFF));
double cTemp = (temp / 65536.0) * 165.0 - 40;
double fTemp = cTemp * 1.8 + 32;
// Send humidity measurement command
device.write((byte)0x01);
Thread.sleep(500);
// Read 2 bytes of data
// humidity msb, humidity lsb
device.read(data, 0, 2);
// Convert the data
int hum = ((data[0] & 0xFF) * 256 + (data[1] & 0xFF));
double humidity = (hum / 65536.0) * 100.0;
// 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:
HDC1000 can be employed in heating, ventilation and air conditioning (HVAC), Smart Thermostats and Room Monitors. This sensor also finds its application in Printers, Handheld Meters,Medical Devices,Cargo Shipping as well as Automotive Windshield Defog.