Capacitor location - TMP36

While this relates to temperature sensors, the question pertains to the application of capacitors.

I notice that another tutorial on TMP36 sensors places the capacitor across the 5v supply and GND, as opposed to the analog signal and GND - are both valid?

A Capacitor across the +5 and Ground will smooth the supply and a capacitor across the analogue signal and ground will smooth the analogue output.

By smooth I mean take out any AC rectified to DC ripple for the +5 and Ground and for the analogue signal, for higher uf caps, slow down the response and produce an averaging effect on the on the analogue signal.

For low (0.1uf) Caps spikes will be removed.

Thanks. I guess I meant to ask is there any advantage adding a cap to supply and analog, thereby smoothing out the voltage and analog output. Perhaps no practical benefit with Arduino board 5v?

The capacitor will effectively buck fast changes to the signal

geoland:
Thanks. I guess I meant to ask is there any advantage adding a cap to supply and analog, thereby smoothing out the voltage and analog output. Perhaps no practical benefit with Arduino board 5v?

On an Arduino a analog output pin is a digital on/off PWM signal and there should be no capacitor added to that signal. Only if you trying to convert the digital PWM signal to a pure DC voltage would one consider adding a cap, but even then only as part of a low pass filter requiring also a resistor and most likely a op-amp.

Hanging bypass caps from pins like Vcc, Avcc, Aref is common practice and has good engineering reasons. Hanging caps off I/O pins is seldom correct unless one is doing something unusual and understands the why and how to do it.

Adding caps to circuits is not like using salt and pepper where one seasons to ones taste.

Lefty

For example, pin A1 is connected to TMP36 centre analog pin to read temperature. Not PWM or output but analogRead. Would this be an exception?

I think neither is needed in this case.
If you art. Worried about power fluctuations affecting the reading, hang it from vcc to gnd. But the 5v is already well regulated and filtered on the arduino board.
A cap on the output is probably wrong.

I took the time to test it out. In this application driving a TEC with SMPS a cap analog to GND produces more accurate readings.

I don't know if this matter has been settled (elsewhere?), but I have nailed it down sufficiently for my current project, which uses a TMP36 potted with epoxy in a metal probe to measure water temperature. My solution has two parts:

1 - a 0.1uF capacitor from Vout to ground will clean up the output dramatically, another capacitor from Vin to ground seems to do nothing insofar as Vout is concerned

2 - a function - readTmp36() - that returns the average of several readings over a period of time. The attached simple (it uses delay() for timing, so don't try to use it in a real application) test code illustrates the concept, and posts results via Serial.print. Note that the test function posts the average reading, the high and low values, the difference (range), and the exponential moving average (ema) of the difference. On my test bed, the ema without the 0.1uF capacitor runs from 8 to 20, indicating a wide variation in tmp36 readings. The ema with the capacitor generally runs from 1.0 to 3, indicating far more consistent (hence more likely to be accurate) readings, e.g.:

readTmp36() low:214 high:214 avg:214 range:0 ema:1.341
1.04492 volts, 54.49 C, 130.09 F
readTmp36() low:214 high:215 avg:214 range:1 ema:1.319
1.04492 volts, 54.49 C, 130.09 F
readTmp36() low:214 high:214 avg:214 range:0 ema:1.234
1.04492 volts, 54.49 C, 130.09 F
readTmp36() low:213 high:214 avg:213 range:1 ema:1.219
1.04004 volts, 54.00 C, 129.21 F
readTmp36() low:213 high:214 avg:213 range:1 ema:1.204
1.04004 volts, 54.00 C, 129.21 F
readTmp36() low:213 high:214 avg:213 range:1 ema:1.191
1.04004 volts, 54.00 C, 129.21 F
readTmp36() low:222 high:223 avg:222 range:1 ema:1.179
1.08398 volts, 58.40 C, 137.12 F[/quote]

FWIW, I verified the temperatures calculated from the tmp36 readings (over a range from 18C to 90C) against a real SGA glass/mercury laboratory thermometer (yeah, I've still got one), and they were right on the money.

The attached code is provide AS IS, with no warranty expressed or implied!

I hope this is helpful...

tmp36.ino (3.84 KB)

1 Like

At the risk of... Additional filtering on both the supply rail and the output are very much OK... that having been said a 10 to 100 nF cap on the analog output is quite ok for a number of reasons related to both code and implementation and a 10 uF cap on the Vcc rail is quite OK if only from the standpoint of "It Can't Hurt". By pass capacitors are "Magic" bullets and should be used generously. They draw no power and are invisible to anything besides noise. If more than that is required or you need to "Bang" on the software you might well have some hardware wiring issues and some of those can be problematical. The biggest one being a computer connected to the board causes the ground reference to be changed and if there are other ground referenced items connected this could well be an issue. Clip on Ferrites are often very helpful in combating common mode noise and sometimes dual coil common mode chokes similar to the ones used for mains filtering are helpful. Probably the biggest issue is good grounding policies. A Star topology is most effective for low noise. All grounds and all power for that matter should be connected in that manner rather than the more common and BAD daisy chaining that is more commonly used. If a module, connected as a daisy chained unit draws more current that it's fellow modules it will create a voltage drop in both power and ground lines and all the other modules so connected will share this drop or "Noise" voltage. It isn't usually an issue with an Arduino that is wired and bypassed properly except for things that can occur concurrently Serial and A/D are things that the processor (to the best of this Noobs knowledge) does asynchronously and as such "might" be affected. Most if not all "Cross-talk" is just that BUT it occurs through bad wiring practices and through the power wiring rather than signal or control wiring unless the (Again) wiring isn't what it should be, It's a bad idea to place a long wire on any high impedance analog or digital input even a 100K pull down will work wonders. Common sense and a little reading is the general cure... But Real Men, don't read manuals...

Doc

{Edit, Doc}

The TMP 36 and the LM34/5 series of thermal measurement devices are Very accurate (Better than a DS18B20) But they do require some knowledge to use properly. My recommendation is a well bypassed device (1 to 4R7 uF cap on the supply rail and a 1 to 10 nF cap on the output) driving a voltage follower and here I use LMC662's because I am familiar with then and they are RR input devices that work well to either rail for the output. The reasoning is simple a VF has an Exceptionally high input impedance and a Very low output impedance thus making accuracy and level shifting very simple things to do and there is an advantage here as with a VF long wires can be used between the device and the Arduino. and that's not an opinion, I've proved it to myself often enough.

Doc

Thanks for your input! As an electronics novice (albeit with 50 years of systems programming experience), I need all the help I can get. Although the Arduino provides far more processing power than is necessary for this application, I hate wasting CPU cycles on something easily accomplished with a proper hardware design.

I suspect (as you suggest) that the TMP36 reading fluctuations may be an artifact of the USB powering/grounding the Arduino, and the TMP36 connected to the arduino +5v, GND and A/D pins, an inherent "daisy chain" ground loop of sorts. Will verify later today...

Connect your O'scope ground lead (Probe) to the ground on the board and measure the Vcc or 5V source (you'll need an "Isolated" (read battery) supply for this as you don't want to "Add" another ground loop. Then note the level of the stuff (crap) you are seeing on the supply line, the stuff you know shouldn't be there... then unplug the USB port from the Arduino and note the change. What you are seeing is the stuff added by the ground loops. Note that it isn't really there. Try this, write a simple sketch to read the analog0 input and tie the analog0 input to the 3V3 source. Map the readings or not as you choose I don't think it will make a great deal of difference and note that the reading is stable. Now connect anything that is powered by mains power and note the difference on the 5V source and note that the 3V3 reading is stable but the noise changes. What you are seeing is a big ground loop and it is instructive in that If you wrote the simple sketch to measure the 3V3 source the measurements were stable. The instructive point here isn't in the noise measurements, it is in the concept of grounding in general and one of the main reasons I use a Star topology for all interconnections to the Arduino. Noise is easy to generate and hard to eliminate especially if it is a part of the project interconnections. I would also note here that this is very much an issue with any of the positive supply lines as well. All power wiring ground and supply should use the Star wiring concept.
I should say at this time that the Star thing won't fix all or even a few of the issues involved with using an Arduino, it will however prevent many of the issues that can occur without it.

Doc

I understand.

Next I'm going to get off topic for this forum, and suggest that we should take the conversation offline (email to diemkae@gmail.com): do you have a suggestion how I might acquire an inexpensive scope? I'm on a VERY limited budget (retired, fixed income, etc)...

Thanks

You can find Tektronics scopes for sale on Ebay in the sub $100 range. I bought my Tektronics 2213 for $55.00 + shipping ($30.00 is typical, depends where you live).
The 2213 is a 60 MHz (3db) dual channel triggered sweep oscilloscope and a good item to have around. The 2235 is a 100 MHz (3db) dual channel scope. These aren't Logic Analyzers but Good basic analog scopes that are really durable and reliable too.
The Military surplus versions are ruggedized to a point as well. Typical prices today are in the $100 - $200 range and there are other less known bargains.
A Tektronics 465 scope can be found for less than $100.00 (some in calibration too) and as any of the more seasoned visitors here will attest to is a darn good scope with a 180 Mhz Sweep, the vertical amplifiers are down about 8 to 10 db... But it will stably lock up on a 100 mV 180 Mhz sine wave. That used to be the way I qualified a bench scope, especially the Tek 465, If it passed that test most of it was good and the only failures were the power supply electrolytics... besides normal wear and tear... and Dirty Switches. Tektronics is Famous for dirty switches and there is only one good cleaner for that... "Deoxit D5" at $15.00 to $20.00 for a 5oz can is the very best But it ain't cheap. It's based on fish oil and is really unique.
For most microprocessor related things a digital scope is great however for things Analog there is nothing like an analog scope. The only real thing to remember is that the vertical amplifiers, analog or digital should have a rise time that is 10X greater that the rise time of the signal being measured... for best measurements slower is ok but you have to keep in mind the fact that the vertical amplifier can smear what you might be looking for all over or miss it entirely. IMO

Doc