Introduction: Raspberry Pi - TMP100 Temperature Sensor Java Tutorial

About: We are a group of makers. We work in IoT, IOS app, android app, embedded design, sensor design, raspberry pi, arduino, beaglebone, particle electron, particle photon, Bluetooth.

TMP100 High-Accuracy, Low-Power, Digital Temperature Sensor I2C MINI module. The TMP100 is ideal for extended temperature measurement. This device offers an accuracy of ±1°C without requiring calibration or external component signal conditioning. Here is the demonstration with a java code using Raspberry Pi.

Step 1: What You Need..!!

Step 2: Connection:

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

// TMP100

// This code is designed to work with the TMP100_I2CS I2C Mini Module available in Dcube Store.





public class TMP100


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


// Create I2C bus

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

// Get I2C device, TMP100 I2C address is 0x4F(79)

I2CDevice device = Bus.getDevice(0x4F);

// Select configuration register

// Continuous conversion, comparator mode, 12-bit resolution

device.write(0x01, (byte)0x60);


// Read 2 bytes of data

// temp msb, temp lsb

byte[] data = new byte[2];, data, 0, 2);

// Convert the data to 12-bits

int temp = ((data[0] & 0xFF) * 256 + (data[1] & 0xF0)) / 16;

if(temp > 2047)


temp -= 4096;


double cTemp = temp * 0.0625;

double fTemp = cTemp * 1.8 + 32;

// Output data to screen

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

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



Step 4: Applications:

Various applications incorporating TMP100 low power, high accuracy digital temperature sensor include Power-Supply Temperature Monitoring, Computer Peripheral Thermal Protection, Battery Management as well as office machines.