PWM fans causing temp sensor (TMP36) erroneus values (interference?)

Hi all, my first post here.
Trying to learn Arduino programming by working on my first project.

I tried asking the question on Arduino stack exchange but I haven't received all that much input there (arduino uno - PWM fans causing temp sensor erroneus values (interference?) - Arduino Stack Exchange) and I hope that the community here may be able to help me.

Basically I am trying to control PWM chassis fans (their speed) based on temperature.
I'ce got everything setup and code logic seems to work fine. Instead I am having problems with the temperature sensor TMP36 that was included in the official Arduino begnner's kit.

So, I have connected the fans exactly as in the picture in the attachement. Taken from
Picture source

The temperature sensor is a TMP36 (included in the official Arduino beginner's kit). It is connected to +5V and GND on the Arduino Uno R3. Middle pin is the output and is connected to A0 on the Uno.

Temperature readings seem to work well up until the point the fans start spinning. When they do, the output pin on the TMP36 sensor outputs junk values. Such as 0V or 700mV and it fluctuates up and down al the time if I try probing it with a multimeter. When fans some to a stop however, the output once again stabilizes to a fairly correct value.

I am no expert in electronics interference, but electric motors I suppose cause some electrical noise? I had hoped that PC Chassis fans would already have electric components inside the hub to prevent such though... Currently I am trying to run 2 fans at the same time but I wish to use 10-17 later once this works.

The fans I am using are Arctic 92mm PWM Rev 02.

I have checked the datasheet (Datasheet TMP36) for TMP36 (TO-92 package type) and tried adding a ceramic 0.1µF capacitor between +5V and GND and also add resistor of varying values to the output pin. I believe I got some stabilization out of it but not enough. Especially when the fans start spinning faster than 20% duty cycle on pwm it starts to flip out.

I have tried to disconnect power to fans to check if PWM signal may cause it too, but this is not the case as the TMP36 remain stable with PWM on but fwith ans disconnected.

Can someone please help me with explaining what is probably going on and how I can mitigate the problem in a preferably easy way? Do I need to add diodes, capacitors, resistors? Where? Or should I change to a different temperature sensor (which)?

Thankful for help!

If... you did connect the fans like on that picture, then where did you connect TMP36 ground to.
The TMP36 can't share ground with any other device (fans), because that would add interference.

It is wise to power a TMP36 from the 3.3volt pin (cleaner) instead of the 5volt pin.
And read the sensor with 1.1volt Aref enabled in setup(), for a higher resolution.

You didn't post any code, or real picture of the setup.
Says you're using 4-pin fans, but the Fritzing shows 3-pin fans.
Leo..

You can use a LDR with resistor, that will always work.
A TMP36 will almost never work. It has a voltage output and the Arduino uses the 5V as reference by default. That means if the 5V changes, than you will read other temperatures. A workaround is using the 1.1V internal reference as Wawa wrote.

My advice is to stop using the TMP36. It causes too much problems because of the analog voltage output. Use a DS18B20. That sensor has a digital interface to the Arduino board. You need two libraries for that sensor: DallasTemperature and OneWire. Both libraries are in the Library Manager of the Arduino IDE. It is accurate to ±0.5°C, regardless of changing voltages.

Wawa wrote about grounding, and asked to show a photo of your project. My feeling tells me as well that you have a grounding problem. Perhaps you are using a breadboard with the same ground path for the TMP36 and the fans.

17 fans * 0.15 A = 2.55 A
That means you need for example a 12V 5A power supply.

Thanks for the replies!

Aaah, yes it is true that I have the ground connected to 5V and the same ground as the fans. So I guess you are right about the interference on the ground.

3.3V, that I can try, thanks, but where would I connect the ground of the TMP36 then - would it not still be on the same ground as the fans? I'm not entirely sure about how the Aref 1.1V works or is, will have to read up on that somewhere. Or if you have feel that you can explain it in a good way, I would be very thankful of course.

About the 4-pin fan but the picture showing 3-pin: it is just that the picture does not show the tachometer signal wire. It shows +5V, GND and PWM wires.

I don't have my code around here now, but codewise I am basically doing an analogRead(A0) and converting the voltage to a temperature as described in the "love-o-meter" exmaple project in the beginner's guide book from the Arduino kit. But I can try to post the Setup() code at least when I get hold of it. Also I can try to take a picture of the setup if I manage to get a good shot of it.

Koepel:
Okay, the DS18B20 might be interesting if I don't get the TMP36 to work. But what about a resistive thermal probe instead (like the ones attached by a long wire to household digital thermometers), would that be a viable simple option? Sure, still an analog voltage reading, but considering that the LDR was stable, maybe such a probe would be stable too then if it also is resistive?

Right now I am not powering 17 fans yet, only two. Max current draw via clamp meter shows 0.3A @ 12V.

Connect the TMP36 to the Arduino board without anything else connected to those wires. Use a seperate breadboard if you have to. Connect the wires from the fans (PWM signals and GND wires) to the Arduino board without inferering with something else.

The internal 1.1V reference is steady, and that results into steady temperatures. Since the 1.1V is low, you can only measure up to 60°C.

At Adafruit they have an example that uses an external reference and they connect AREF to 3.3V. That gives the full temperature range, but it can damage the AREF if you do it wrong.

For the DS18B20 it takes some time to learn how to use the libraries. If you want ±0.5°C then using a DS18B20 will give you that accuracy. For example for a room temperature or for a sous-vide.

For specific situations a NTC or thermocouple can be used.
A NTC or similar resistive temperature sensor also requires that the circuit must be okay. It also requires calculations. A NTC does not output a certain voltage, but a relative voltage. The Arduino measures a relative voltage as well (when using the 5V as reference) . Therefor that part is easier, but the calculations are harder and you need to know the constants of that NTC for the calculations.

For more accuracy, there are also chips that can measure ±0.1°C accurate.
For less accuracy, just one or two diodes is enough for about ±3°C accuracy. It is possible to connect a single 1N4148 diode to a analog input with nothing else and measure the temperature. It requires a lot of tuning to get ±3°C accuracy.

There are many good options :smiley: as long as you avoid grounding problems :wink:

To avoid ground loops, connect the fan supply and all the fan power wires to two star points (+ and ground).
And use one single wire from the ground star to Arduino ground.

Connect TMP36 ground to the other ground pin of the Arduino.

This sketch shows you how to use the internal 1.1volt Aref (for an Uno).

I agree with using the DS18B20.
Leo..

// TMP36 temp
// connect TPM36 to 3.3volt A0 and ground
// calibrate temp by changing the last digit(s) of "0.1039"

float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  analogReference(INTERNAL); // use internal 1.1volt Aref
  Serial.begin(9600);
}

void loop() {
  tempC = ((analogRead(A0) * 0.1039) - 50.0);
  tempF = tempC * 1.8 + 32.0; // C to F
  Serial.print("Temperature is  ");
  Serial.print(tempC, 1); // one decimal place
  Serial.print(" Celcius  ");
  Serial.print(tempF, 1);
  Serial.println(" Fahrenheit");

  delay(1000); // use a non-blocking delay when combined with other code
}

ThreadRipper:
3.3V, that I can try, thanks, but where would I connect the ground of the TMP36 then - would it not still be on the same ground as the fans?

Same ground - different point.

You best connect the fans to GND as close as possible to the power supply. Ideally at the power supply. Then a separate ground wire from that same point to the Arduino, and all your sensors to the Arduino board's ground. This way you keep the high current of the fans away from your Arduino.

I'm not entirely sure about how the Aref 1.1V works or is, will have to read up on that somewhere.

Start here.

It's basically the 100% point of your ADC. So for the TMP36 switching to the very stable 1.1V internal reference you have a more stable voltage (Vcc will change a bit when you switch on the fans, so your 100% level changes and all other measurements are off), and your signal has a larger range of analog values, so better precision.

Do note that this 1.1V is +/-10% so you have to calibrate for best results. The actual value varies per board, but is very stable.

Thank you all for your input, highly appreciated! I believe I have managed to solve the problem more or less!

I rewired the TMP36 to 3.3V and connected GND to the ground next to the Aref pin on the Uno. At first nothing seemed to have changed except I did not get any 0V outputs from the output pin when fans spun up. Instead the reported temperatures would drop from 25C to 14C or so and fluctuated a bit.

Then, I realized that my "power supply" is a dinky Chinese one really. I guess it started creating a lot of ripple as the load increased slightly as fans started spinning. (Perhaps a large a enough capacitor across its output would have been able to stabilize it?)

So I bought a Vanson variable voltage universal DC power adapter and that made all the difference! :slight_smile:
Now it is very stable, but I notice that from time to time I do get one reading that is a few degrees higher (such as 28.5C when it has been reporting 25C previously multiple times in a row). But I believe it should no longer be the power supply perhaps.

My next test will be to connect more fans and see if the stability will be maintained.
Thanks everyone!