Help with Temperature sensor TMP36

I am using a single Arduino to power the TMP36 from the A0 analogue out pin. I also am using the arduino to power a simple DC fan that is being controlled by a transistor coming off of one of the digital I/Os. The sensor's reading will change drastically when the fan is running. For example, I can let the sensor get to steady state (reading about 25C, room temp) with the leads of the fan unplugged. When I plug in the leads, the senor jumps up to a steady state value around 34C. Then immediately when I unhook the leads of the fan, it jumps back down to room temp. Because of my understanding of how this sensor works (measuring voltage change), powering another component shouldn't affect the reading. Does anybody know what I could be doing wrong?? Thanks!

Improper power supply. Voltage drops when you switch on the fan.

Do a search on this forum - it's a very common issue with this sensor (and the TMP35).

Use the 1.1v internal reference and that problem should go away. See @wawa example. You should use the 1.1v reference anyway for better accuracy and precision. You may have other problems - what is the motor's current demand? Which Arduino are you using and how are you using it to power the motor?

Hi Hhuda

You confuse me (not difficult) when you write,

I am using a single Arduino to power the TMP36 from the A0 analogue out pin.

I would have expected you to use one of the Arduino's power outlets. Can you post a circuit diagram - even hand drawn? It would help me a lot.


Hi Vagulus,

Sorry about that - as I read my own question I agree I didn't do a good job explaining. I have the TMP36 powered through the +5V source on the Arduino and then grounded. The control wire is going into the A0 analogue input.

Also from the 5V source I have powered a fan (simple DC motor). This actually goes through a transistor. The base of the transistor is controlled by one of the DC Outputs, allowing me to control the fan.

The schematic below from Adafruit's website is my exact setup, without the TMP36. My circuit is that shown below, with the TMP powered and grounded on the same sources with the control lead going into A0 analogue input.

Again, the issue I am having is the reading from the TMP36. When the fan turns on (i.e. digital output = HIGH into the base of the transistor), the temperature reading will jump about 10 degrees.

Thanks in advance for trying to help, and sorry for my inability to properly explain this the first time!

The ADC gives you the ratio of the voltages at AREF and A0, i. e. ADCvalue = (A0 / AREF) * 1024.
You have not shown your code but I assume you are using 5V as reference like this

  analogReference(DEFAULT); // use Vcc as analog reference

So if AREF drops then your ADCvalue rises.
Measure the voltage at the 5V pin and at A0 with a multimeter in both conditions (motor running/stopped)

As DaveEvans already explained in post#2...
You should use the internal 1.1volt reference (code only).
Post your code (inside code tags) if you want help with that.

Also, don't share sensor ground pin with fan/transistor ground pin.

Powering the fan off the +5V pin is also a bad idea. Use an external supply for that. Most fans draw more power than the on-board regulator can supply (or if powering from a computer USB port you don't use the regulator, but will still be drawing too much power for the USB port to supply - a USB mobile phone charger should do better already).

Thanks in advance for trying to help, and sorry for my inability to properly explain this the first time!

At my level of understanding I can't really say that I am trying to help :o , it'd be more truthful to say that I am trying to understand your problem. :slight_smile: To that end, I too would like you to post the code you are using (as Wawa requested). A link to the "Adafruit's website you mentioned would also be nice - I have had a look around but didn't see anything like this project.

My limited experience tells me that you might be expecting more precision and consistency from the TMP36 that the hardware is capable of providing. My next thing would be that driving a fan from the 5V Arduino outlet is also a bridge too far as I see wvmarle pointed out.

This is a very common problem with these sensors as I pointed out already. I see it all the time. This, and other analog sensors with an absolute voltage output.

The sensor itself is accurate enough. The Arduino's ADC as well. It's just that you have to understand how the things all work together.

An ADC measures voltage against a reference, the reference being the full scale. So if your input remains the same voltage, but the full scale voltage changes, the output changes.

Normally full scale reference is Vcc = 5V.
TMP35 output say 250 mV.
Then the ADC will produce 0.25*1024/5 = 51.

Code will calculate this back to 250 mV, and show 25 C.

Now switch on the fan, and due to the load Vcc drops to say 4.5V.
TMP35 output is still 250 mV but now full scale is 4.5V.
Then the ADC will produce 0.25*1024/4.5 = 57
Code will calculate this back to 280 mV and show 28 C.

Now you see how the temperature changes with Vcc. And you will also see another problem: the very low voltage compared to full scale.

So switch to the 1.1V internal reference, a value that's independent of Vcc, and the problem disappears. As added bonus, you have a greater resolution as you have about 1 mV per ADC point, instead of 5 mV per ADC point.

A link to the "Adafruit's website you mentioned would also be nice - I have had a look around but didn't see anything like this project.

It's this one, and it does say here that a motor can draw too much power for the USB and Arduino should then be powered from a wall adapter.

Personally, I think even trying to power a motor from the Arduino 5V pin, regardless of how the Arduino itself is powered is bad practice.

I'd always go for this approach with separate power to the motor, even if the motor is a 5V one.

Changing from default Aref to the more stable 1.1volt Aref is basically adding one line in void setup()

analogReference(INTERNAL); // call 1.1volt Aref

(assuming you're using an Uno or Nano)

Then the 5volt value in the maths line that converts A/D value to temp has to be changed from 5 to 1.1
Anything else needed depends on the code you're using.
Post it.

The breadboard approach as suggested by Adafruit is another problem - many such breadboards can not handle currents over about 500 mA (too high internal resistance, too thin conductors). So again small motors may work, any larger motor not.

With their small 250 mA motor you can get away with powering it through the 5V pin and connecting through a solderless breadboard - it's still not a good idea.

You can share the power supply between Arduino and the motor, as long as you have the motor wired in parallel to the Arduino, so the current doesn't flow through the Arduino.