(Very first build) Temp sensor going crazy

Hello, I'm a chemist and know next to nothing about programming and circuit building. I just bought the UNO along with a Hall Effect sensor, photoresistor, and a temp sensor to try and learn a bit more

I was excited when I got the board, and copy and pasted in the Blink LED code to see if it worked, which it did.

I then followed this tutorial Temperature sensor tutorial - Using the TMP36 / LM35

and set up the simple temperature sensor circuit. I changed the power to 3.3V instead of 5, and changed that in the code...but I'm getting huge fluctuations in the temperature and was wondering if the code is bad...or more likely my temp sensor is bad? Would a resistor somewhere in the circuit cut out noise in the power supply?

Here is what im getting back in the serial port monitor:

216.96 degress F
1.83 volts
133.05 degress C
271.48 degress F
1.50 volts
99.85 degress C
211.74 degress F
1.29 volts
78.91 degress C
174.03 degress F
1.46 volts
95.66 degress C
204.20 degress F
1.98 volts
147.55 degress C
297.59 degress F
1.62 volts
112.10 degress C
233.78 degress F
1.48 volts
97.92 degress C
208.26 degress F

:frowning:

ALso, how do you make the board STOP running something? I've tried hitting the reset button and also the stop button on the arduino software...but it keeps going as soon as i let go of the reset button. I have to manually unplug the power cable which is a little annoying. Thanks for the help!!!

Is YOUR temperature sensor connected to analog input 0 or analog input 1?

ALso, how do you make the board STOP running something?

Upload an empty Sketch, disconnect power, hold the processor in reset, or add a "run" switch to a pin with the appropriate code in your Sketch.

thanks for the reply.

the temp sensor is in analog pin 0

And you're certain your Sketch is reading from analog input 0?

I'm pretty sure that's in the first line.

//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures

/*

  • setup() - this function runs once when you turn your Arduino on
  • We initialize the serial connection with the computer
    */
    void setup()
    {
    Serial.begin(9600); //Start the serial connection with the computer
    //to view the result open the serial monitor
    }

void loop() // run over and over again
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);

// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 3.3 / 1024;

// print out the voltage
Serial.print(voltage); Serial.println(" volts");

// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degress C");

// now convert to Fahrenheight
float temperatureF = (temperatureC * 9 / 5) + 32;
Serial.print(temperatureF); Serial.println(" degress F");

delay(5000);}

With the board disconnected from power ... Disconnect the temperature sensor from ANALOG IN 0. Connect a wire from GND to ANALOG IN 0. Apply power.

Is the reading stable? What is the reading?

-58.00 degress F
0.00 volts
-50.00 degress C
-58.00 degress F
0.00 volts
-50.00 degress C
-58.00 degress F
0.00 volts
-50.00 degress C
-58.00 degress F

So it's stable. I put the circuit back together and switched to the other ground plug..still crazy numbers. Could it be from a bad power supply? Or maybe the 3$ sensor is just crap. I can't find my multimeter or I'd try it that way

So it's stable.

Which also means the Arduino is very likely OK.

I put the circuit back together and switched to the other ground plug..still crazy numbers. Could it be from a bad power supply?

You're using either the 3V3 or 5V on the board? If yes, then the power supply is very unlikely to be the problem. Both those are regulated.

Or maybe the 3$ sensor is just crap.

That is certainly a possibility and looking more-and-more like the culprit.

I can't find my multimeter or I'd try it that way

That would definately be helpful. You could then determine exactly where the problem lies.

There is one other thing you can try. There may be digital noise that needs to be maanged...
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

But that's also unlikely. I believe the Arduino includes de-coupling capacitors.

Are you sure you have the same sensor as found in the tutorial?
Some sensors communicate rather than just output a voltage.
If it's different, post what it says on the sensor.

Also post your connection hi-res picture.

Regarding the second image: Every breadboard I've used has the connections running the other direction (along the lettered rows).

How do the connections run on your breadboard?

Coding Badly, I think you're right. Looks like the breadboard would run the other way. I think the A0 is floating.

It's actually a breadboard that's from the Radio Shack electronics learning kit--found here RadioShack.com Official Site - America's Technology Store

What's strange is that even when I DIDN"T have access to that breadboard the first night, I used a piece of paper I propped up, and just poked the 3 prongs of the temp sensor through the paper, then placed the 3 wires in the paper next to the correct temperature prongs. I still got the same whacky readings.

What does A0 floating mean?

I probably should have tried just switching the code to = 1 and plug the wire into A1..

What does A0 floating mean?

A pin (like A0) that is unconnected on one end does not have a determined state; the pin can "float" between states. Basically, the pin picks up electricity from the surroundings so the value read is based on the charge the pin has accumulated.

To prevent a pin from floating it has to be driven to a specific state; like connecting it to GND or 5 V or to the temperature sensor.

The traces in the breadboard are in the horizonal and not in the vertical, "rotate" the sensor to have one pin in each leterred line and try again.

Ok, I rotated the sensor 90 degrees and now I have the 3 prongs in 3 different lettered rows, and the corresponding wires plugged in correctly.

I changed the port to A1 and I changed the first line of code from = 0 to = 1 so it samples from the correct port.

Now, at least I"m getting stable voltages...but the wrong temperature...so perhaps its somewhere in the math that's written into the code? Notice I also changed the original 5V to 3.3 where it says so in the code

0.47 volts
-3.27 degress C
26.11 degress F
0.47 volts
-3.27 degress C
26.11 degress F
0.46 volts
-3.59 degress C
25.53 degress F
0.47 volts
-3.27 degress C
26.11 degress F
0.46 volts
-3.59 degress C
25.53 degress F

On a side note I put my 2 fingers on the top and rounded edge of the temp sensor, and saw an increase of 0.01 V every 15-20 seconds...stopped doing it after it only moved 0.04 V in over a minute though. It got up to 0.51 V, and within 10 seconds of taking my finger off it dropped back down to 0.47 V...so it seems to be responding and is stable at room temp, just not doing the conversion correctly

I'm glad to see a Chemist interested in electronics stuff. Here's what I observed, with your hi-res picture and code.

Your sensor is TM36. It's got a 0.5V offset on the degC reading. You used your finger as a probe and characterized the increase. This tells you the probe is working. All are good. All you need to do is to change that 3.3 into 5 on this line of your code. I calculated for you, with this change your reading is around room temperature.

float voltage = reading * 3.3 / 1024;

Your arduino must be a standard arduino on 5V power supply. Did you change the 5 into 3.3?

EDIT: 21 C for room temp is good in this case, as it's a little cold where I am sitting out in this sun-room
EDIT: On second thought I've been sitting in this computer chair all day so I'm probably cold from not being active as well...even though it is cold in this room. I'm lacking another temperature reading device to corroborate.

OK so I did what any good scientist shouldn't do, I changed the formula around until I got the equation to give me the answer I wanted.

I changed the 5V to 3.3V on purpose so I could use lower power as I thought that had something to do with the readings.

I also changed the (voltage - 0.5) *100

to (voltage - 0.23) *100 after I plugged in the stable voltage I was getting (0.45 V) and replaced 0.5 with X and solved for it. Now with that modified, I am getting these readings, notice how quickly the temp increases as well with my fingers on the probe

Each Reading is 10seconds apart

71.23 degress F
0.45 volts
21.79 degress C
71.23 degress F
0.45 volts
21.79 degress C
71.23 degress F
0.50 volts
26.95 degress C
80.51 degress F
0.51 volts
27.92 degress C
82.25 degress F
0.51 volts
28.24 degress C
82.83 degress F
0.49 volts
25.98 degress C
78.77 degress F

NOTE- Here is updated code. Changes from original are highlighted--Original can be found on original post

//TMP36 Pin Variables
int sensorPin = 1; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures

/*

  • setup() - this function runs once when you turn your Arduino on
  • We initialize the serial connection with the computer
    */
    void setup()
    {
    Serial.begin(9600); //Start the serial connection with the computer
    //to view the result open the serial monitor
    }

void loop() // run over and over again
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);

// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 3.3 / 1024;

// print out the voltage
Serial.print(voltage); Serial.println(" volts");

// now print out the temperature
float temperatureC = (voltage - 0.23) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degress C");

// now convert to Fahrenheight
float temperatureF = (temperatureC * 9 / 5) + 32;
Serial.print(temperatureF); Serial.println(" degress F");

delay(10000); //waiting a second
}