## Using a 1N4148 diode as temperature sensor…

November 21, 2011 | Arduino, electronics | By: Mark VandeWettering

I had an application where I wanted to detect temperature. No big deal, lots of good temperature sensors exist. But of course, I don’t have any of those. Rather than order something from sparkfun, I thought I’d just try to see what I could do with the stuff I had on hand. What I had on hand was about 100 1N4148 diodes that I got for about a penny a piece.

The idea is that the forward voltage of diodes is temperature dependent. For every degree Celcius the diode increases, the forward voltage should drop by 2mV. So, I decided to test this idea. I configured the analog input pin 0 on my Arduino to be an input, and then activated its internal pullup resistor. I then wrote a program which averaged a bunch (1000) of readings in an attempt to get a stable, relatively noise free signal.
I logged the values beginning at room temperature, then held the diode between my fingers, and then released it a couple of times. Here’s a graph of the resulting data values:

You can see that when I grab the diode, the forward voltage drops rather quickly, but when I release, the signal returns to the original value, somewhat more slowly. Room temperature in my house is around 70 degrees (21 degrees C) and body temperature is 98.6 is about 37 degrees C. The difference would then be about 16 degrees C, and we might expect a difference of 32 mV, but I experienced a difference of only about 16mV. At least part of this can be attributed to the fact that your finger temperature isn’t actually that close to 98.6.

This simple experiment demonstrates a couple of problems: the values returned by analogRead() are noisy, and quantization error is significant. The analogRead call returns a 10 bit number, which means that each bit is about 4 mV, or about 2 degrees C. We could use an operational amplifier to multiply the voltage to make it easier to read, which might help. Consider that an experiment for the future.

Comment from Kragen Javier Sitaker
Time 11/21/2011 at 12:21 am

You know, the ATMega microcontroller also has an onboard temperature sensor; you can select it as the data source for the ADC.

Another idea, for more precision: presumably the leakage current in a back-biased diode is temperature-dependent, no? You could back-bias the diode and then measure how slowly the voltage decays. If it decays too fast to detect, you could add more capacitance in parallel.

Comment from Mark VandeWettering
Time 11/21/2011 at 12:47 am

I didn’t know that! Thanks for pointing it out to me.

Comment from Lee Felsenstein
Time 11/21/2011 at 12:58 am

You should also be able to configure the Atmel AVR processor to use its internal 1.1V band-gap reference voltage as the analog reference, this expanding the 10-bit range to 1.0742 V per bit. The Arduino compiler may not provide this function, though. It has to be done as part of the programming process – can’t be done through an application program (as everything in Arduino is, I believe, done.

Comment from Nick G8INE
Time 11/21/2011 at 1:51 am

Hi Mark,

Your post about using the 1n4148 took me back – I worked for the Post Office briefly a long time ago, early 70s or so, and used a diode to monitor temperature in the exchange over night, we hooked the output up to a pen recorder so that we could see what happened at 0200 when we had a rash of unexpected failures. It showed that a spike that was occurring, and that it coincided with the MUGS (motorised Uni group selectors) dying.

As far as I can recall, it was a simple 741 circuit with the diode in one leg and a reference voltage on the other, probably not especially accurate or linear, but did the job at the time !!

regards

N.

Comment from Ricardo Martins
Time 11/21/2011 at 8:57 am

I won’t pretend I know anything about digital signal processing, but I found an ebook about it yesterday and one of the examples in the ebook’s site about the usefulness of DSP is similar to your problem with noisy signal. It’s the second example here: http://www.dspguide.com/new/appexam.htm

The gist of it is that this problem can be alleviated (or even solved) by increasing the sampling rate, using a low-pass filter to eliminate the noise and then using decimation to bring the sampling rate back down to whatever you need.

I hope this helps.

Comment from Ricardo – CT2GQV
Time 11/21/2011 at 3:12 pm

PN junction on a 2n2222 transistor also works nice with a bonus you can solder the metallic outer case.
Used them (1n4148) for temperature control on a rf amplifier (http://speakyssb.blogspot.com/2010/03/jbot-2-temperature-control.html).

Comment from Mark VandeWettering
Time 11/22/2011 at 6:56 pm

Hey Ricardo! I like your blog! 🙂

I have seen the 2n2222 trick a couple of times. If memory serves, Stu Phillips (Ethergeist blog) used it to heat a crystal for his WSPR transmitter. I could have tried it, but I have a lot more 1N914s at the moment. 🙂