Objective: use a temperature sensor and 7-segment LED display to build a digital thermometer.

You will need: Arduino UNO (or similar), a Microchip MCP9808 sensor on an Adafruit I2C breakout board, 10k potentiometer, Adafruit 4-digit 7-segment I2C display, breadboard and patch cables.


Picture of Adafruit MCP9808

This project shows how you can use a building-block technique to make a digital thermometer using the I2C bus. The temperature sensor is a pre-built Adafruit MCP9808 PCB and displays the temperature on an Adafruit 4-digit 7-segment LED display. Both items are delivered as a kit and you will need to solder the various components together - instructions are on the Adafruit website.

Assembling The Components

Picture of potentiometer soldered to Veroboard

The potentiometer is connected across the GND and +5V lines and creates a voltage divider that allows you to adjust the calibration of the thermometer by adding or subtracting a temperature value. The sketch reads the analogue input from the wiper on the pot and calculates a temperature value of between -2.5C and +2.5C which is added to the actual temperature that was read. This amount of correction is more than sufficient to correct the output from the MCP9808, which is usually ±0.25C. The pot, however, is optional and can be omitted, though you will need to amend the sketch so that it does not read pin A0 because the value may float unless tied to ground. I use ceramic pots and, to make it easier to fit them on to a breadboard, I solder them to a small piece of Veroboard first and then attach a piece of single-row header as shown here.

The Sketch

The Arduino reads the temperature, converts it alternately to degrees Celsius and Fahrenheit, works out which characters are required in each position and then displays the temperature. The standard LED functions will display integer, hex and floating point values but we need a composite display showing a numeric value and then C or F as appropriate, for example, -5.6C or 69.0F. The actual range of displayable temperatures is currently -9.9C to 99.9F. If you need a greater range then you would need to omit the decimal and just display -10C or 100F, for example. Alternatively, you could add a second LED display to have up to eight characters.

The Fritzing library does not yet contain the MCP9808 and so I have put a comment box instead. The connections are in the correct sequence for just plugging the MCP9808 into the breadboard.

Fritzing diagram of connections

Changing The I2C Address

Setting I<sup>2</sup>C address

The MCP9808 has a default I2C address of 0x18. However, you can change this to between 0x19 and 0x1F by connecting one or more of the A0, A1 and A2 connections to VCC. The MCP9808 has pull-down resistors on each address connection and setting them to VCC will change the address. A0 will add 0x01 to the base address of 0x18, A1 will add 0x02 and A2 will add 0x04. For example, to set the address to 0x21 you would connect A0 and A1 to VCC to give 0x18 + 0x01 + 0x02 = 0x21.

You can download the Arduino sketch from here.

By taking a copy of the sketch and modifying it, you can create a more useful program that perhaps reads humidity from an appropriate sensor and displays that too, or reads temperatures from a number of sensors.