Introduction: Raspberry Pi TMP112 Temperature Sensor Python 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.

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

Step 2: 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 python code for TMP112 can be downloaded from our GitHub repository- Dcube Store.

Here is the link for the same :

The datasheet of TMP112 can be found here:

We have used SMBus library for python code, the steps to install SMBus on the 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 in Dcube Store.

import smbus

import time

# Get I2C bus

bus = smbus.SMBus(1)

# TMP112 address, 0x48(72)

# Select Configuration register, 0x01(1)

# 0x60A0(24736) Continous Conversion mode, 12-Bit Resolution, Fault Queue is 1 fault

# Polarity low, Thermostat in Comparator mode, Disables Shutdown mode# Normal mode, 12-bit data

data = [0x60A0]bus.write_i2c_block_data(0x48, 0x01, data)


# TMP112 address, 0x48(72)

# Read data back from 0x00(0), 2 bytes, MSB first

data = bus.read_i2c_block_data(0x48, 0x00, 2)

# Convert the data

temp =(data[0] * 256 + data[1]) / 16

if temp > 2047 :

temp -= 4096

cTemp = temp * 0.0625

fTemp = cTemp * 1.8 + 32

# Output data to screen

print "Temperature in Celsius is : %.2f C" %cTemp

print "Temperature in Fahrenheit is : %.2f F" %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.