Thermocontroller TMP102 Syntax

Hi folks.

Just received my TMP102 and have no clue how to go about reading it.

Not too sure what to do here. I have 3.3V and GROUND hooked up, but don't know the pinouts. Says a 2 wire serial configuration, so I am guessing the 2 pins on the small side.

I've found no code, don't know how to approach this (I'm a beginner).

Any advice appreciated.


It’s an I2C device :wink: so good luck :slight_smile:
This is not the easyest way to get temperature data (Two-wire serial interface)

You have to read arduino tutorials on I2C a.k.a. two wire serial.
start by using wire.h at the top of the sketch

I googled around and found this code:


#include <wire.h> 

int led = 2;

int ptrTemp =  0b00000000;         // TMP102 register pointers
int ptrConf =  0b00000001;
int ptrTLow =  0b00000010;
int ptrTHigh = 0b00000011;
int i2cAddr;                        // used to set address on the chip 

void setup()
  Wire.begin();                     // join i2c bus (address optional for master)
  i2cAddr = 0b1001001;              // ADD0 pin connection selects one of four possible addresses

void loop()
  Wire.beginTransmission(i2cAddr);  // select temperature register
  Wire.send(ptrTemp);               // (if only temperature is needed this can
  Wire.endTransmission();           // be done once in setup() )

  Wire.requestFrom(i2cAddr, 2);     // request temperature
  byte byte1 = Wire.receive();
  byte byte2 = Wire.receive();    
  Wire.beginTransmission(i2cAddr);  // select temperature register
  Wire.send(24);  // (if only temperature is needed this can
  Wire.endTransmission();           // be done once in setup() )

  Wire.requestFrom(i2cAddr, 2);     // request temperature
  byte lowbyte1 = Wire.receive();
  byte lowbyte2 = Wire.receive();    
 /*  T_High REGISTER 
  Wire.beginTransmission(i2cAddr);  // select temperature register
  Wire.send(28);    // (if only temperature is needed this can
  Wire.endTransmission();           // be done once in setup() )

  Wire.requestFrom(i2cAddr, 2);     // request temperature
  byte hibyte1 = Wire.receive();
  byte hibyte2 = Wire.receive();    
  int tempint = byte1 << 8;         // shift first byte to high byte in an int
  tempint = tempint | byte2;        // or the second byte into the int
  tempint = tempint >> 4;           // right shift the int 4 bits per chip doc
  float tempflt = float( tempint ) * .0625; // calculate actual temperature per chip doc
 //  Low_temp  
  int lowtempint = lowbyte1 << 8;         // shift first byte to high byte in an int
  lowtempint = lowtempint | lowbyte2;        // or the second byte into the int
  lowtempint = lowtempint >> 4;           // right shift the int 4 bits per chip doc
  float lowtempflt = float( lowtempint ) * .0625; // calculate actual temperature per chip doc

//  Hi_temp
  int hitempint = hibyte1 << 8;         // shift first byte to high byte in an int
  hitempint = hitempint | hibyte2;        // or the second byte into the int
  hitempint = hitempint >> 4;           // right shift the int 4 bits per chip doc
  float hitempflt = float( hitempint ) * .0625; // calculate actual temperature per chip doc

  Serial.print( "Temp: C = ");
  Serial.print( int( tempflt ) );
  int tempF = (tempflt * 9/5) + 32;
  Serial.print( " F = ");
  Serial.print( int( tempF ) );

  Serial.print( "   Low:  C = ");
  Serial.print( int( lowtempflt ) );
  int lowF = (lowtempflt * 9/5) + 32;
  Serial.print( " F = ");
  Serial.print( int( lowF ) );
  Serial.print( "   Hi:  C = ");
  Serial.print( int( hitempflt ) );
  int hiF = (hitempflt * 9/5) + 32;
  Serial.print( " F = ");
  Serial.println( int( hiF ) );
  if ( tempflt > hitempflt )

Hope it helps


Thanks for the post.

Just out of curiosity, do most breakout modules like this one come with instructions? I have a schematic and a manual, but nothing that I can find that helps with any integration.

Not sure if that wink by the 12C device is a warning or not. Is that something special?

Anyway I'll look over the code, see if I can get her to work.

What should I be looking for with respect to temperature? I get the impression there are easier ways.


According to the schematic, SDA is the pin (pin 2) next to +3.3V, and SCL is the pin (pin 3) next to the GND pin.

Most I2C devices come with instructions of some kind, usually a bit lower level programming than the arduino, so tempting to do i2c as first project is definetly harder to as the i2c requires a bit understanding of the inner workings of the Arduino IDE c-language. but when libraries for a specific I2C device have been made for the Arduino, then it is just a matter of calling functions from ready made library with one command instead of writing a few lines and loops to communicate.

Ordinarily you use 3 pin temp sensor with Vin, Vout and Ground and one just reads the Vout pin directly with just one command (; ) and calculate the temp from the readout.


Ah, that's what I was hoping for, the Vin, Vout and ground. Oh well.

I have to review the C reference and brush up on this language.


This temp sensor is mainly for people who do not have analog inputs availeble I think, as it is just so much easyer to read analog signal. But with this sensor there is no doubt what temperature it is for the sensor sends the exact value. versus analog where you have to consult tables and make a formula to calculate temp.

There are not so many analog pins on the arduino and the AD converter is only 10bit, so the resolution is only 1024 steps

Your sensor is 12bit and as such you have much better potential resolution for the temp sensor. THis is an another reason why one wants to use i2c interfacing, talking from arduino to devices with high bit resolution and get all the nuances of the data processed back.


Actually that’s a good point. Eventually I need to monitor a whole bunch of items, and control them. At this point, it’s too new to me to say that I will need multiple Arduino boards to do what I do. Digital pins are aplenty, especially on the new new MEGA (3.0?). Have you seen that model? Double the double row’d digital pins on the end. I’ve only seen a picture of it once. But if I have to hook up 2 MEGAs, and run them from 1 unit, then that’s fine. 1024 steps is more than fine for what I need anyway. But again, I don’t know how far I am going to pack this system with data acquisition and control.

Essentially half a C resolution is fine for me. Every one of these has to be calibrated anyway, so that essentially comes down to calibration anyway.

On top of that I will need many other sensors that I am not finding. Either that, or I have the wrong design. Essentially I am needing the following:

  • temperature in a fluid
  • flow rates
  • single atmosphere pressure (<14 psi)
  • specific gravity (0.800 to 1.200)
  • some kind of proximity…to measure height of a fluid inside a stainless steel tank…harsh environment

That’s all I can think of right now. Going to be fun putting all this together.


Actually I wil be doing a bachelors degree in process chemistry this spring, so those are excactly the kind of problems I like :) I have a mega myself.

Most common with flow rates is mesuring diffrential pressure drop when the fluid passes through an Orifice in the pipe, so you use a DP-cell to do this

Using an absolute pressure sensor you get the 1atm value

Specific gravity is mesured with pressure of a known volume: you have a known volume or more specific a height of liquid over the sensor. So the pressure at the depth corresponds to weight at a specific volume + 1 atm, this is pressure on a cell minus the atmospheric pressure. This type of sensor is also a DP-sensor or dp-cell :)

So to sum it up: You mesure the spesific gravity by having a dp sensor at a known depth of the liquid you can get spesific gravity. Or if you use another method to mesure the fluid level like capacitive sensing rod, sonar, or whatever then you combine that with the dp-sensor at the bottom of the tank to get specific gravity

You have a diffrential pressure sensor at the bottom of the tank, probably just before the oulet valve, this will give you the height of the liquid when combined with specific gravity.

Make a thin stainless steel box for your temperature sensor where the sensing elements touch the wall of the box, and submerge in the tank


I did a degree with some Chemical Engineering about 20 years ago (ironically in touch with 2 of my classmates over the past 2 days), and I wanted to chase up automation. I am a brewer.

For SG, fermenters will have varying levels of batch heights. That would have to be taken into account. Also, to be in this harsh environment and resistant to cleaning procedures. Thin stainless won't cut it, as it will be gone soon. Usually we use a thermowell and shove a thermocouple in there. Maybe I can find one I can integrate.

Anyway, I will have to design all that.


Well, one time i made me some "wine" (distilling), i just placed my thermometer on the boiler-tank and wrapped insulation (wool blanket) around it, and it worked :) the temperature was good enaugh for my purposes. That batch became 99.9 % PURE ALKOHOL it was distilled 4 times and I used drying medium in the last 3 times to break the azetrope and get it purer (just proof of consept, not for human consumption, just lab work) now I have built a plate column with 8 thermometers, boiler condenser, reflux and flow into the column controled with peristaltic pumps.

All my thermometers are thermopcouples! (hard to find other types in the chemical process industry)

I can take product from any of the sections to condenser. I have plans to make NIR (poormans version with handpicked filters)or somthing similar attached to the top to mesure what I have in the compsition (detect unwanted components and know the strength).

My wife gets a bit mad when I take the distill up and when I make a batch of "wine", so mostly it stays dismantled in a box in the garage ;)

Cheeers, happy brewing


Ya that’s a Coffee still. Nice work.

Anyway, just got the hardware for my first project, but I’m waiting on 4 thermoprobes from the US. I might have to rig something up for these items…

Just the probe part. I have 4 of them for my smoker:

  • meat 1
  • meat 2
  • meat 3
  • smoker temp

I want to control the amount of air that goes into the smoker, hence controlling the combustion. I will be choosing a schedule, depending on the temperature of the smoker. I want to be able to set the target temperature, then have the system respond accordingly. The smoker should take about 5 minutes to respond, so that’s a challenge. Any idea how I work that out? I have a basic idea of the schedule and how it behaves on a similar smoker, so I can use that as a guideline.

I am assuming analog resistance given a voltage on these thermometers will provide feedback. I don’t know the normal working voltages on these, but I can find out. The fan is 12 volts, so I have to rig up something to power the fan, and the arduino. I might go for a Mini Pro for this project. Displays take up so much effort and pins though.

Sounds like what you need is PID control, that's the industry's holy grail of control. It deals nicely with the time delay. Fortunaly there has been made a PID library for the arduino: the discussion on the forum when it was put out:

Just leave the Derivate part out and use only Propotional and Integral methods. The D part homes in on the setpoint in ever smaller steps to try to reach the setpoint, the I part calculates the residuals and tries to eliminate accumulated errors.

If the PI overshoots the heat by too much when you set a new setpoint, you might consider the full PID control as it dampens the overshoot of the controller.

When the D-part is wrongly tuned it can make random errors bigger. i.e. a random error in mesurement will result in bigger error in controller.

Tuning is a science in it self but you might want to go for manual online methods like Ziegler-Nichols or somthing like that.

PID should give you a "rock" steady control and is prefered over on/off methods as it gives smaller errors.


OK, thanks for the heads up. I will give it a review.


thanks for sharing.