Temperature changing with different power sources.

So, I have my arduino connected to my computer through USB. I have a TMP36 temperature sensor connected to the arduino and i also have a series of 12 LEDs (3 green, 9 red) connected to it. At the moment i have the Arduino configured and programmed to detect the current temperature and display it in a sort of retro analogue style with the leds, in a sort of bar graph style where the green LEDs represent the 10s place and the reds indicate the 1s place. It's pretty cool if i say so myself :P 8). It works perfectly fine when connected to my computer and displays a temperature which happily matches that of a conventional, non electric, analogue thermometer. But there's an issue. When i unplug the USB connection and replace it with a 9v battery powersource so as to portable-ize my creation and show off to unsuspecting victims, the indicated temperature suddenly rises about 2 degrees and then stays at that temperature for a bout 5 minutes. Then the temperature begins to rise uncontrollably as if possessed by a spirit hell bent on making me look a fool. At one point the Arduino was displaying a temperature of 38 degrees celsius in a room that definitely wasnt. Distraught by this sudden turn of events, i rushed back to my lair and plugged the kit back into my laptop. I kept the 9v plugged in as well. I quickly typed up a "serial.print(temp)" command, compiled and uploaded this to the arduino. I opened up the serial monitor and found that it too was displaying wacky temperatures. This indicated to me that it was not a fault with the LEDs nor did the flaw lie in the code. I have a hunch that the problem is caused by the TMP36 or the powersource. This seemed odd at first to me because the TMP36 is connected to the 5V pin on the board and therefore it seemed like it should receive the same voltage regardless of the power source. Can anyone shed some light onto my plight? 8) Thanks!

To those with short attention spans:

TMP36 outputs pretty stable 25 degrees when arduino is connected to computer through USB TMP36 outputs 27 degrees when arduino is connected to 9v battery and then the indicated temperature continues to rise all the way up to the forties.

help plz? ty

There is a lot you can do.

Do you have a multimeter ? If not, buy one. The cheap ones of 5 euros/dollars are not very good, but it's better than no multimeter at all.

What is the voltage when only powered by the USB bus ? It might be 4.7 V or so. That will influence the reading with analogRead(), which is accurate if the voltage is +5.0V.

Is your adapter 9V regulated ? Some adapters of 9V actually are 14V with small loads. Check also the temperature of the +5V voltage regulator on your Arduino board. Try another adapter.

You can measure the Vout of the TMP36. That should not be drifting. If the +5V for the TMP36 is stable, the Vout should be stable.

There is a lot more you can do to get to the problem, but I think it has to do with the voltage. If that is all good, and you still have a problem, you could upload a photo and your sketch.

edit: It's a 9V battery, not an adapter. Your battery probably can't supply the current.

Monitor the voltage on the 9V battery to see if it is dropping as the temperature rises.

Pete

according to this datasheet: http://www.analog.com/static/imported-files/data_sheets/TMP35_36_37.pdf the output will be below 1.1V (750mV for 25°C and 1100mV for 60°C and 100mV for -40°C)...

so u could use the built-in voltage reference: http://arduino.cc/en/Reference/AnalogReference

but most important is that the battery can deliver the power needed... how about a little solar panel? the arduino is too hungry for a battery... :)

Thanks for your help everyone! I think what ive concluded from your replies is that the 9v battery provides insufficient voltage to the board and therefore the TMP36 is giving a false reading. I'll look into getting a proper 9v power adapter. In the meantime I suppose I will just have to keep the Arduino connected to my laptop through USB. :( Although I will see if maybe some of the solutions you suggested can fix my problem including checking the voltage of the power source and the 5v pin on the board and i will try out the analogReference command that Riddick suggested. again thank you all for the help! :)

Here is a breadboard diagram of my current setup.
Please excuse the general awfulness of the diagram :stuck_out_tongue:

Here is a picture of the arduino displaying a temperature of 23 celsius

kewl

how does the heat radiation of those LEDs affect the TMP36? or r those LEDs cool?

In the circuit diagram, why do you have a resistor going from Arduino ground to the ground rail on the breadboard? If that is the only connection between the two grounds, it is wrong. It should be a wire.

Pete

Why do the leds have no resistors ?