Temperature Sensor TMP102 with arduino

So after playing around with the Humidity sensor, it was natural for me to start playing with a simple temperature sensor. For my project, I choose the TMP102 sensor. The main reasons for choosing this sensor were:

a) I was working with a 3.3V Arduino, so I wanted a sensor that I could interface directly.

b) This sensor has great resolution, it is quite cheap (for less than $6) and sparkfun has a breakout board for the same.

c) It allowed me to play some more with the I2C interface.

20110930-033001.jpg

Arduino makes it really straightforward to play with I2C with its Wire Library that is very well documented . The sensor has multiple modes and lot of additional functionality that can be configured over I2C.

This sensor also has an additional pin that can be used to get 4 different addresses on the I2C bus. In my experiment, I connected it to GND to get an address of 72.

Great Getting Started Tutorial is available from buildr website. I have just wrapped this code around a simple library that can be downloaded from here. This library currently works with the sensor in basic mode ( I will be updating it soon to allow access to the sensor’s extended functionalities).

UPDATE: The library for Arduino 1.0 and higher can be downloaded from from here

Below is some sample code to use the sensor:

#include "WProgram.h"
#include "Wire.h" // Required to talk to the sensor and read values
#include "TMP102.h"  //TMP102 library

using namespace std;

TMP102 tmp102;

void setup()
{
    Wire.begin();
    tmp102.setup(); // Currently not required, but future versions of library will use it to set modes
    Serial.begin(9600);
}

void loop()
{
    // Get Temperature
    float tempC = tmp102.getTemperatureCelsius();
    float tempF = tmp102.getTemperatureFahrenhiet();
    Serial.println(tempC,2);
    Serial.println(tempF,2);
    delay(5000);
}

int main(void)
{
	init();
	setup();
	for (;;)
		loop();
	return 0;
}

2 responses to “Temperature Sensor TMP102 with arduino

  1. Very nice! Im glad to see our code was helpful.

    Though I think the “main” function is needed. The arduino software does all of that for you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s