Pages: [1]   Go Down
Author Topic: Arduino Uno + TMP102 sensor + AnalogWrite?  (Read 627 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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! smiley Here is the code that I am using:

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

void setup() {               
  Serial.begin(9600);
  Wire.begin();
  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: ");
    Serial.println(val*0.0625);
  }
}
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8967
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Full Member
***
Karma: 0
Posts: 113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Thanks!
Logged

Texas
Offline Offline
Edison Member
*
Karma: 25
Posts: 1298
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged

Good luck, Jack

Offline Offline
Full Member
***
Karma: 0
Posts: 113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

Did I mention that I love arduino & its awesome community? smiley-wink

Thanks again!!
Logged

Pages: [1]   Go Up
Jump to: