Introduction: Raspberry Pi TMP112 Temperature Sensor Java Tutorial

TMP112 High-Accuracy, Low-Power, Digital Temperature Sensor I2C MINI module. The TMP112 is ideal for extended temperature measurement. This device offers an accuracy of ±0.5°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..!!

Picture of What You Need..!!

1. Raspberry Pi

2. TMP112


3. I²C Cable

4. I²C Shield for Raspberry Pi


5. Ethernet Cable

Step 2: Connections

Picture of Connections

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 TMP112 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 TMP112 can be downloaded from our github repository- ControlEverythingCommunity

Here is the link for the same :

The datasheet of TMP112 can be found here:

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.

// TMP112

// This code is designed to work with the TMP112_I2CS I2C Mini Module available from





public class TMP112


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


// Create I2C bus

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

// Get I2C device, TMP112I2C address is 0x48(72)

I2CDevice device = bus.getDevice(0x48);

byte[] config = new byte[2];

// Continous Conversion mode, 12-Bit Resolution, Fault Queue is 1

config[0] = (byte)0x60;

// Polarity low, Thermostat in Comparator mode, Disables Shutdown mode

config[1] = (byte)0xA0;

// Write config to register 0x01(1)

device.write(0x01, config, 0, 2);


// Read 2 Bytes of data from address 0x00(0), msb first

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

// Convert data

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

if(temp > 2047)


temp -= 4096;


double cTemp = temp * 0.0625;

double fTemp = cTemp * 1.8 + 32;

// Output to screen

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

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



Step 4: Applications..:

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


About This Instructable



More by Dcube Tech Ventures:Home Automation with Raspberry Pi using Relay boardMotion Control with Raspberry Pi and LIS3DHTR, 3-Axis Accelerometer, using Python3-Axis Accelerometer, ADXL345 with Raspberry Pi using Python
Add instructable to: