Difference between revisions of "TMP102"

From MyLabWiki
Jump to: navigation, search
Line 21: Line 21:
== Example Code ==
== Example Code ==

Revision as of 23:18, 12 June 2010


The TMP102 is a two-wire, serial output temperature sensor available in a tiny SOT563 package. Requiring no external components, the TMP102 is capable of reading temperatures to a resolution of 0.0625°C.

The TMP102 features SMBus and two-wire interface compatibility, and allows up to four devices on one bus. It also features an SMB alert function.

The TMP102 is ideal for extended temperature measurement in a variety of communication, computer, consumer, environmental, industrial, and instrumentation applications. The device is specified for operation over a temperature range of –40°C to +125°C.

TMP102PinConf.png TMP102Diagram.png

Note that the TMP102 is a 3.3V device and will require a Logic Level Converter (Sparkfun) to connect it to a 5V Arduino.


The TMP102 is a 3.3V device and therefore it is connected to the Arduino board through a Logic Level Converter.


TMP102-top.jpg TMP102-bottom.jpg


Example Code

The following code snippet reads the temperature from the TMP102, converts the raw value to degrees Celsius and Fahrenheit, prints it on an LCD display and sends it to the serial port.

 #include <LiquidCrystal.h>
 #include <Wire.h>
 // initialize the library with the numbers of the interface pins
 LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
 byte res;
 byte msb;
 byte lsb;
 int val;
 float tC;  // temperature in Celsius
 float tF;  // temperature in Fahrenheit
 void setup()
   // set up the LCD's number (col,row): 
   lcd.begin(20, 2);
 void loop()
   /* get new value from TMP102 */
   res = Wire.requestFrom(72,2);
   if (res == 2) {
     msb = Wire.receive(); /* Whole degrees */ 
     lsb = Wire.receive(); /* Fractional degrees */ 
     val = ((msb) << 4);   /* MSB */
     val |= (lsb >> 4);    /* LSB */
     /* calculate temperature */
     tC = val*0.0625;
     tF = (tC * 9/5) + 32;
     /* show temperatures on display */
     lcd.setCursor(0, 1);
     Serial.print("C   ");
   else {