LM35 - wrong readings when fan is turning

Ive been using arduino and some shields to learn about electronics for a few weeks now.

I have a little project that is giving me problems:

I'm trying to turn on / off a fan according to the temperature.

I'm using a LM35 for temp readings (works fine on it's own) and a TIP122 to PWM the fan

When I start the program the LM35 reads a correct temperature.
But when the temp rises and the fan kicks in the LM35's reading shoots up +/- 6°C
The moment the fan is disconnected the LM35 readings go back to normal.

also adding this in the code helps:

    analogWrite(fanpin,0);
    delay(100);
    Serial.println(((5.0 * analogRead(2) * 100.0)/1024.0));
    analogWrite(fanpin,intfanpower);

Turing of the fan every time i want to read temps will reduce the fan life to much.

This is how everything is wired up:

See page 9 of the LM35's datasheet http://www.ti.com/lit/ds/symlink/lm35.pdf and add the capacitors/resistor per figure 15 and see if it helps.

Use the average of 5…1000 analogRead().

How much current does the fan draw?
Do you get this problem if the fan is connected to an external power supply (with grounds connected of course)?
You really should have a snubbing diode and a 100nF capacitor across the fan.

The problem is almost certainly caused by using a common ground wire for the fan and the LM35. Remove the black wire connecting the LM35 ground pin to the ground rail of the breadboard, and replace it by a wire direct from the ground pin of the LM35 to one of the two Arduino ground connections that you are not currently using.

Thank you for the replies!

So here are the things I tried and didn't change the behaviour:

  1. snubbing diode (will add it in the final design)
  2. using an average read (in the complete sketch i already do that)
  3. adding a caps and resistors to the lm35
  4. putting the lm35 on a direct ground pin on the arduino board

What did work:

  • putting the fan on a seperate power supply with connected grounds (i used a 9v battery)

Can anyone explain why this worked?
Will adding a cap over the fan while i'm PWMing not screw up the PWM? Doesn't it make more sense to do this over the power supply?

The problem is almost certainly caused by using a common ground

+1
Never, never, never use commun wire ground between a LM35 and other component.
Use Star ground configuration, common point (center of the star) must be the Arduino.

Also, in Arduino board, Aref pin location is very bad and the Aref line, too long, acts as an antenna.
I improve the mesurment stability by adding a capacitor dirrectly on the micro socket between Aref and ground.
→ on the figure there is two capacitors, only this solded to the socket is usefull.

With this capacitor no average is needed : mesurment are absolutly stable

Forum12.png

deleenheir:
What did work:

  • putting the fan on a seperate power supply with connected grounds (i used a 9v battery)

Can anyone explain why this worked?

When you turn the fan on, the power supply voltage drops because of the additional load. You were powering the fan directly from the Arduino +5V supply, so the Arduino’s 5V supply dropped a little. But the 5V supply is the default analog reference. So when you turn the fan on, the reference voltage decreased, causing your analog reading (for a fixed input) to increase.

If you want to use the same 5V power supply for the Arduino and the fan, then you can use the 3.3V supply as the analog reference instead, provided that you never need to measure more than 3.3V on the analog inputs.

deleenheir:
Will adding a cap over the fan while i’m PWMing not screw up the PWM? Doesn’t it make more sense to do this over the power supply?

IMO adding a cap in parallel with the fan is a bad idea, because it will cause high current surges in the TIP120 (and screw up the PWM if the cap is large enough). If the fan uses a brushed DC motor, then you should definitely add a flyback diode in parallel with the fan. If it uses a brushless motor, then a flyback diode may not be needed, but will do no harm.

then you can use the 3.3V supply as the analog reference instead, provided that you never need to measure more than 3.3V on the analog inputs.

Yes is better for the accuracy, but as a LM35 gives 1V for 100 °C you can also use the internal reference (1.1 volts +/- 10%)

analogReference(INTERNAL);

Notice that when selected the internal reference is dirrectly connected to Aref (see datasheet).
You have the possibility to mesure it with a voltmeter.

Remember wires are just low-value resistors - when any appreciable current flows the voltage at the two
ends of the wire will be different. This is why you keep high-current paths away from sensitive analog
sensors and amplifiers.

Even with thick wires the connections can exhibit substantial resistance if of poor quality, dirty, or corroded.

68tjs:

then you can use the 3.3V supply as the analog reference instead, provided that you never need to measure more than 3.3V on the analog inputs.

Yes is better for the accuracy, but as a LM35 gives 1V for 100 °C you can also use the internal reference (1.1 volts +/- 10%)

analogReference(INTERNAL);

Notice that when selected the internal reference is dirrectly connected to Aref (see datasheet).
You have the possibility to mesure it with a voltmeter.

I had already been thinkering with the internal analog reference.

The disadvantage is that it messes up the first analog readings and i have to switch back and forth between 'internal' and 'default' because there are also some pot-meters to regulate the temp threshold and temp delta.

I will be running this project on a stand alone ATTINY85.

If my power supply is stable enough I should not have any problems with the LM35? The power supply i had in mind is an old switching USB-charger (1A).
I also ordered some DS18B20. Will these be less fragile in the circuit?

MarkT:
Remember wires are just low-value resistors - when any appreciable current flows the voltage at the two
ends of the wire will be different. This is why you keep high-current paths away from sensitive analog
sensors and amplifiers.

Even with thick wires the connections can exhibit substantial resistance if of poor quality, dirty, or corroded.

Maybe a dumb question: But how do I achive that when using just one power supply?
Does that mean realy separating everything? 2 power supplies 2 grounds and a relay to switch the high current circuit?

deleenheir:
I had already been thinkering with the internal analog reference.

The disadvantage is that it messes up the first analog readings and i have to switch back and forth between ‘internal’ and ‘default’ because there are also some pot-meters to regulate the temp threshold and temp delta.

The first analog reading should be considered unreliable anyway. Do an analogRead call at the end of setup() after changing the reference, and throw the result away. To avoid problems with the pots, connect them to whatever voltage you are using as the analog reference, instead of +5V.

and how can i connect the pots to the 1.1 internal voltage?

AREF pin

LarryD:
AREF pin

So you are saying that if i set analogreference to INTERNAL the arduino will output 1.1V on the Aref pin?

nevermind, my question was answered here:

68tjs:

then you can use the 3.3V supply as the analog reference instead, provided that you never need to measure more than 3.3V on the analog inputs.

Yes is better for the accuracy, but as a LM35 gives 1V for 100 °C you can also use the internal reference (1.1 volts +/- 10%)

analogReference(INTERNAL);

Notice that when selected the internal reference is dirrectly connected to Aref (see datasheet).
You have the possibility to mesure it with a voltmeter.