[Solved] Temporary drop in reference voltage (SD card/TMP36 logger)


I've got a bit of a problem. I'm making a TMP36/SD card temperature (and photoresistor) logger. The logging itself (2 second interval) can be started and stopped with the press of a button. Here's the code:

The problem that I'm having is that when I press the button (which results in the data.txt file being opened and measuring+writing starting) the reference voltage drops from 4.99 v to 4.91 v (measured with a multimeter). This obviously causes a wrong temperature to be written to the SD card. The voltage stays at 4.91 v for a few measurements and then returns to 4.99.

When I press the button again (closing the file and stopping the measurements) it stays at 4.99 v. Then when I press the button (opening the file again and resuming measurements) it again drops to 4.91 for a while before going back to 4.99. Et cetera.

Anyone who knows how I can solve this?


The output of a TMP36 should NOT be compared to the potentially unstable 5volt supply (default Aref),
but to one of the internal reference voltages of the (unspecified) Arduino.
This has been explained many times on this site, and your code even has the commented lines prepared for that.
//#define aref_voltage 1.111

Also, ground wire of the TMP36 must not be shared with anything else.

I did give it a separate ground. It worked fine without the SD card on the default aref though. But I'll definitely try the 1.1 volt reference. That will severely limit the range though.

That will severely limit the range though.

You haven't told us which Arduino you're using, so I can't give any hard recommendations to 'fix' that.

If you have an Uno, and want to read temps higher than ~55C, then you can connect a suitable resistor between the Aref pin and the 3.3volt pin, and set Aref to EXTERNAL.
The resistor should drop Aref to ~1.75volt, so you can measure to 125C.
It should now have the higher stability of the (unused) 3.3volt supply.

Oh, completely forgot to mention that it is indeed an uno. What kind of resistor would I need to put between the 3.3 volt and aref?

Try 27k or 33k, and measure the Aref pin voltage with a digital voltmeter.
Or see what the A/D returns with different temps (melting ice, room temp, boiling water).

Edit: My Uno measures 1.64volt with a 33k resistor.

It works perfectly now. The reference voltage is super stable. Thanks a lot!

Karma added for posting back.

Now add [SOLVED] in front of the title of the original post.
Do the same for your Dutch cross-post.
Een link naar deze pagine is mischien handig voor de Nederlanders daar.