TMP006 Hookup Guide

This Tutorial is Retired!

This tutorial covers concepts or technologies that are no longer current. It's still here for you to read and enjoy, but may not be as useful as our newest tutorials.

Contributors: JordanDee
Favorited Favorite 2

Talking to the Sensor

Now that the hardware is set up, how do we actually receive temperature data from the sensor? Well, we've got to do some coding. Luckily for you, there isn't much you have to modify if you want to get up and running immediately, however we'll explain the overall gist of how the code works in this section.

Here is the download of the example code we'll be using. You can also find the most up-to-date code on GitHub. Feel free to dive right in and try to use it or follow along for an overview.

In the beginning, we have two global variables. One stores the I2C address of the sensor, and the other stores how many times we'd like the sensor to sample per temperature reading/calculation. Feel free to try the defaults right away with the hardware setup described in the last section, no changes necessary. Here they are:

uint8_t sensor1 = 0x40; // I2C address of TMP006, can be 0x40-0x47
uint16_t samples = TMP006_CFG_8SAMPLE; // # of samples per reading, can be 1/2/4/8/16

If you'd like to use multiple sensors, you'll need to declare another sensor variable and give it the appropriate address. Feel free to change the sample rate regardless. Just keep in mind, the more samples it takes, the longer you have to wait for a reading. It's about a 1 second wait per 4 samples.

Next, let's examine the setup loop. Here we initialize serial output so we can display our readings. We also call a configuration function for our TMP006 sensor. It sets up some defaults for us to get going and also tells the sensor how many samples per reading we want. If you're using more than one sensor, you'll have to call this function for each one with the appropriate I2C address.

void setup()
  Serial.println("TMP006 Example");

  config_TMP006(sensor1, samples);

Within the loop function, we call two main functions. The first gives us the temperature of the object in front of the sensor, and the second gives us the temperature of the sensor itself. Both are then sent via serial to your computer and can be viewed using the Serial Monitor. Again, you'll need to add duplicates of these functions if you're talking to multiple temperature sensors.

void loop()
  float object_temp = readObjTempC(sensor1);
  Serial.print("Object Temperature: "); 
  Serial.print(object_temp); Serial.println("*C");

  float sensor_temp = readDieTempC(sensor1);
  Serial.print("Sensor Temperature: "); 
  Serial.print(sensor_temp); Serial.println("*C");

  delay(2000); // delay 1 second for every 4 samples per reading

Running this code with the default configuration and the basic hardware hookup, you will see both the object and sensor temperatures displayed on the serial monitor every two seconds.

Exploring the Gorier Details...

So you want to learn more about the details of what's going on in the background? Read on!

There are two tabs in this example that implement the I2C functionality, I2C_16.h and I2C_functions.ino. These allow the reading and writing of data to the sensor. Take some time to learn about I2C via our tutorial mentioned in the beginning. Also learn some about Arduino's Wire library, as it is what's used to make this communication possible. Of course it is possible to write your own I2C communication from scratch, but the Wire library makes it much easier.

When it comes to acquiring the object temperature, we must make some calculations because the sensor only gives us the thermopile voltage and a raw temperature reading of the actual sensor itself. The equations necessary for calculating object temperature can be found in section 5.1 of the user guide. The TMP006_functions.ino tab includes the various implementations necessary to get temperature readings. The calculations based on the user guide can be found there. Within TMP006.h, you'll find various constants for the calculations, configuration settings, and the sensor's register addresses.

Feel free to explore this code as much as you want, and don't be afraid to modify it to better suit your needs.