Go Down

Topic: Arduino Uno + TMP102 sensor + AnalogWrite? (Read 1 time) previous topic - next topic


Hi guys

I am trying to connect a TMP102 temperature sensor (see http://bildr.org/2011/01/tmp102-arduino/) to my Uno. However, instead of using the pin that says "3.3v", I am trying to use an analog pin through which I send 3.3v to the TMP102. When I do this, though, I keep getting bad data (negative values, even though it is hot where I live), or the serial output just freezes.

Any thoughts on what I may be doing wrong, and/or what is going on?

The wiring that I am using is exactly the same as the one shown above in the example form BILDR, except only for the V+ pin (which I am connecting to pin 11 [through which I am sending 3.3v], instead of the pin labeled "3.3v" in the Uno board). Note that when I keep all the same and move the V+ pin from the TMP102 to the pin labeled "3.3v" in the Uno, all works perfectly...

Thanks so much! :) Here is the code that I am using:

Code: [Select]

#include <Wire.h>
int tmp102 = 11;
byte res;
byte msb;
byte lsb;
int val;

void setup() {               
  analogWrite(tmp102, 175);    // this will make pin 11 send 3.33v

void loop() {
    res = Wire.requestFrom(72,2);
    if (res == 2) {
    msb = Wire.read(); // Whole degrees
    lsb = Wire.read(); // Fractional degrees
    val = ((msb) << 4);   // MSB
    val |= (lsb >> 4);    // LSB
    Serial.print( "  Temp Celsius: ");


Code: [Select]
analogWrite(tmp102, 175);    // this will make pin 11 send 3.33v
analogWrite() uses Pulse Width Modulation.  It turns the output ON (+5V) for some portion of the time and OFF (0V) for some portion of the time.  This is far from a steady 3.33V and probably explains the unexpected results.

You can get close  to 3.33V by using a low-pass filter on the pulsed output to get an analog voltage with some ripple.  I'm sure Google can help with that.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


Hi John

thank you so much for your response. I now understand a little bit more about PWM and the effects on the 3.3v component I am trying to run.

I read several articles I found re. low pass filters (this one was informational - http://provideyourown.com/2011/analogwrite-convert-pwm-to-voltage/), but it gets very confusing very fast, especially as I looked at the online calculator (http://sim.okawa-denshi.jp/en/PWMtool.php).

So... in you & any one else's experience & knowledge, what values should I plug in the calculator to see what value of R and C I would need to connect the TMP102 using the analogWrite function?


jack wp

Why do you not want to use the stable 3.3Volt pin?
It should give you lots more accurate readings.
If you decide to use a PWM to try to get 3.3Volts, then you need to know how much current is being drawn by the TMP102. Do you know?


Hey Jack

thank you for your response. I just learned that I can use the 3.3v pin (as you suggested) in conjunction with a digital pin & a transistor connected to it :)

Did I mention that I love arduino & its awesome community? ;)

Thanks again!!

Go Up