Temperature Monitoring Using MCP9808 and Raspberry Pi

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.

MCP9808 is a highly accurate digital temperature sensor ±0.5°C I2C mini module. They are embodied with user- programmable registers that facilitate temperature sensing applications. The MCP9808 high-accuracy temperature sensor has become an industry standard in terms of form factor and intelligence, providing calibrated, linearised sensor signals in digital, I2C format.

In this tutorial the interfacing of the MCP9808 sensor module with raspberry pi is demonstrated and its programming using python language has also been illustrated. To read the temperature values, we have used raspberry pi with an I2c adapter.This I2C adapter makes the connection to the sensor module easy and more reliable.


Step 1: Hardware Required:

The materials that we need for accomplishing our goal includes the following hardware components:

1. MCP9808

2. Raspberry Pi

3. I2C Cable

4. I2C shield for raspberry pi

5. Ethernet Cable

Step 2: Hardware Hookup:

The hardware hookup section basically explains the wiring connections required between the sensor and the raspberry pi. Ensuring correct connections is the basic necessity while working on any system for the desired output. So, the requisite connections are as follows:

The MCP9808 will work over I2C . Here is the example wiring diagram, demonstrating how to wire up each interface of the sensor.

Out-of-the-box, the board is configured for an I2C interface, as such we recommend using this hookup if you’re otherwise agnostic. All you need is four wires!

Only four connections are required Vcc, Gnd, SCL and SDA pins and these are connected with the help of I2C cable.

These connections are demonstrated in the pictures above.

Step 3: Code for Temperature Measurement:

The advantage of using raspberry pi is, that is provides you the flexibility of the programming language in which you want to program the board in order to interface the sensor with it. Harnessing this advantage of this board, we are demonstrating here its programming in the python. Python is one of the easiest programming languages with easiest syntax. The python code for MCP9808 can be downloaded from our github community that is Control Everything Community.

As well as for the ease of the users, we are explaining the code here also:

As the first step of coding you need to download the SMBus library in case of python, because this library supports the functions used in the code. So, to download the library you can visit the following link:


You can copy the working code from here also:

import smbus

import time

# Get I2C busbus = smbus.SMBus(1)

# MCP9808 address, 0x18(24)

# Select configuration register, 0x01(1)

# 0x0000(00) Continuous conversion mode, Power-up default

config = [0x00, 0x00]bus.write_i2c_block_data(0x18, 0x01, config)

# MCP9808 address, 0x18(24)

# Select resolution rgister, 0x08(8)

# 0x03(03) Resolution = +0.0625 / C

bus.write_byte_data(0x18, 0x08, 0x03)


# MCP9808 address, 0x18(24)

# Read data back from 0x05(5), 2 bytes


data = bus.read_i2c_block_data(0x18, 0x05, 2)

# Convert the data to 13-bits

ctemp = ((data[0] & 0x1F) * 256) + data[1]

if ctemp > 4095 :

ctemp -= 8192

ctemp = ctemp * 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

The code is executed using the following command:

$> python MCP9808.py

The output of the sensor is shown in the picture above for the reference of the user.

Step 4: Applications:

MCP9808 Digital Temperature Sensor has several industry level applications which incorporate industrial freezers and refrigerators along with various food processors. This sensor can be employed for various personal computers, servers as well as other PC peripherals.



    • Party Challenge

      Party Challenge
    • IoT Challenge

      IoT Challenge
    • Fandom Contest

      Fandom Contest