Pages: [1]   Go Down
Author Topic: Diode temp sensor help.  (Read 2462 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all. I have been trying to make a temperature sensor from a diode and my arduino uno. I have done a lot of googling and have got no where. I have tried two different approaches. The first approach with no prior research involves one diode and a resistor. The diode's cathode is connected to the arduino's ground and the diode's anode is connected to a resistor which connects to an arduino digital pin. I then have an arduino analog pin connect to the node between the resistor and the diode to read the voltage. So the equation for temperature is:
T = [ q Vd ] / [ k ln( (Id+Is)/Is ) ]
Where
Id = (Vs + Vd)/R
q = 1.61 x 10^-19
k = 1.38 x 10^-23
Vd is the voltage measured from the arduino analog pin
and lastly Is is the reverse saturation current.

current "Is" is my issue since itself depends on temperature which is what I am trying to solve for. That is where I got stuck on that approach (is the equation a transcendental equation?).

After some research, I found valuable:
page 338 of "The Art of Electronics 2nd ed." and
http://en.wikipedia.org/wiki/Silicon_bandgap_temperature_sensor

For the art of electronics page 338, it shows circuits using transistors, is it possible to NOT use transistors for this project (op amp ok though)?

also looking over some forums online I read that an op amp is needed, is that true?

For my second approach I made two (almost) identical circuits with different resistors. The circuits resemble the one described above. Each circuit has it's own Vd connected to a different arduino analog pin. The resistors differ for each in order to have different currents flow through the diodes. I plan to use the second equation in the wikipedia link above, although I have a feeling that my second approach is super wrong.

Please help me out here. At least direct me where to go. Thank you.
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1010
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The common 1N4148 diode can be used as temperature sensor (but almost every diode will do).
The resistor can be connected to +5V.
For the 1N4148, I used 10k.
Rule of thumb is: 2mV / C    (2mV less voltage drop for every degree increase of temperature)
   0.4 V at +100 degrees Celcius
   0.6 V at 0 degrees Celcius
   0.8 V at -100 degrees Celcius
But you have to test for yourself to determine a more precise calculation. I think that 2 degrees accuracy is possible.

You don't need an Op Amp. The analog input of the Arduino is high impedance, it will never influence your circuit. The variation of the voltage drop is also large enough for a good accuracy. But you have to use the internal reference of 1.1V
http://arduino.cc/it/Reference/AnalogReference
Here 3k3 is used : http://www.openimpulse.com/blog/2012/07/low-cost-diode-temperature-sensor/#more-261
« Last Edit: August 10, 2012, 06:59:05 pm by Krodal » Logged

Montreal
Offline Offline
Edison Member
*
Karma: 23
Posts: 2487
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.openimpulse.com/blog/2012/07/low-cost-diode-temperature-sensor/#more-261
"Step" voltage arduino depends on REFERENCE ADC voltage, to measure 2 mV w/o OPA you should switch reference to internal 1.1V (UNO or ArMega328 board)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much for your help and thanks for the links, all the time spent on google and I was not able to find that link. So it seems my initial hardware connection is correct (so happy!). It also seems I do not need to use the Diode equation (so my software part is wrong). I don't quite understand this "internal reference" thing you guys talk about. So say if i change the internal reference to 1.1V, would that mean that analog max voltage would be 1.1v? If so, why must I do that? Why can I not keep it at 5v and use a higher resistance for my resistor? And lastly, in the link you guys gave me, it says the current has to be arround 1mA, why is that?

Also Krodal said:
The resistor can be connected to +5V.
So, once again, why not keep the internal reference at 5v instead of 1.1v?

Magician said:
Quote
to measure 2 mV w/o OPA you should switch reference to internal 1.1V
What does OPA stand for (op amp?) ? If OPA = op amp then why would I have to use an op amp for 5v and not for 1.1v?

Thanks again.
« Last Edit: August 10, 2012, 09:04:54 pm by TheElder777 » Logged

Montreal
Offline Offline
Edison Member
*
Karma: 23
Posts: 2487
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So say if i change the internal reference to 1.1V, would that mean that analog max voltage would be 1.1v? If so, why must I do that?
Yes, max input voltage would be 1.1V . I don't think you need more with a Si diode. Lowering reference you increasing ADC resolution. For example, with default 5V reference, one "count" ADC is equal to 5 / 1023  = 4.88 mV. Which is high to measure 2 mV raising voltage per degree of temperature.  In other words, ADC would report next value only when changes in temperature about +-2.5 degree. Usually,  amplifier (OPA) required to overcome this issue. 
Quote
Why can I not keep it at 5v and use a higher resistance for my resistor?
Higher resistor value produce lower voltage across a diode.
Quote
And lastly, in the link you guys gave me, it says the current has to be arround 1mA, why is that?
I think it compromise value, from one side (lower current end) there is a leakage:
Quote
For instance, many monolithic temperature sensors have an output of only 1 μA/ ̊K. This leads to a
1 ̊K error for only 1 μ-Ampere of leakage current
  "Application Note 460 LM34/LM35 Precision Monolithic Temperature Sensors"
on the other side - self heating, P = V x I.
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1010
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some basic explanation:

The analog-to-digital converter (ADC) inside the microcontroller converts a signal from 0...5V to a value of 0...1023. To use the ADC, the function analogRead() is used.

The ADC is however capable of more than just that. It uses a voltage reference for the conversion. Normally that voltage reference is +5V. But it can be set to +1.1V.

With a voltage reference of 1.1V, the ADC converts a signal an analog input pin from 0...1.1V to a value of 0...1023. That's roughly 1mV resolution. So the accuracy increases. Nice!
http://arduino.cc/it/Reference/AnalogReference

This is all happening inside the chip.
The voltage reference is connected to the outside world with a pin. On your Arduino Board, you see "AREF", that's the reference.
If you switch to another voltage reference, it is best to wait for 20ms, to let the voltages settle.

Code:
void setup()
{
  analogReference (INTERNAL);   // 1.1V reference
  delay(20);                                // let voltages settle
}

void loop()
{
  int rawADC;
  rawADC = analogRead(some_pin);   // 0...1.1V -> 0...1023
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much. That makes perfect sense. I understand! I will give it a try now (can't wait for it to work, i hope).
Logged

Southern California
Offline Offline
Full Member
***
Karma: 0
Posts: 108
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry to break in, but I read these posts this morning and made a diode temperature sensor just now.  I had no idea you could do this!  I don't know the number of the diode I have, but it works great.  I'm watching the temperature drop a couple of degrees F when the air conditioner comes on, then slowly creep back up.  Thank you all for the information!

(edit - added my code)

Code:
// Diode Temperature Sensor, diode plus 10K resistor
// Written by Tom Fangrow, August 11, 2012

int hotVal=86;      // value with boiling water, 100 degrees C
int coldVal=256;    // value with ice water, 0 degrees C
float slope;

void setup() {
  slope=(coldVal-hotVal)/100.0;     // value per degree C
  analogReference(INTERNAL);        // 1.1 Volt reference
  Serial.begin(9600);
}

void loop() {
  int val = analogRead(0);
  float c = (coldVal-val)/slope;    // Celsius
  float f = 32+c*9/5;               // Fahrenheit
  Serial.println(f);
  delay(1000);
}
« Last Edit: August 11, 2012, 02:29:49 pm by JavaMan » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good stuff JavaMan. I would like to report to Krodal and Magician that I have got my sensor up and running, thank you guys.
Logged

0
Offline Offline
Shannon Member
****
Karma: 162
Posts: 10523
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For consistent results ensure the resistor is 1% or better (lower temp-co), the 5V is regulated and be careful to avoid errors due to self-heating - use low currents.  With the dual pin arrangement you can apply power to the diode for just long enough to take a ADC reading then power it down till the next time - very little power dissipation in the diode then to self-heat it.

Note that different individual diodes will have different calibrations.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For consistent results ensure the resistor is 1% or better (lower temp-co), the 5V is regulated and be careful to avoid errors due to self-heating - use low currents.  With the dual pin arrangement you can apply power to the diode for just long enough to take a ADC reading then power it down till the next time - very little power dissipation in the diode then to self-heat it.

Note that different individual diodes will have different calibrations.

Thanks. Yes, I did my own temperature calibration. I haven't considered powering on and off.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

THANK YOU, THANK YOU, THANK YOU!!!!!

I had a Rainbow Kit that created a DMM thermometer that used a 2222 transistor as a temp sensor, but it also had 2 trimmer pots and ran on 9V Vcc.   I figured some how I could do the similar thing without the trimmers and possibly within the 5V range but I couldn't find anything specific on the Web.  I had a beer brew site that used it but as a standalone with op amps and relays and such, not the Arduino.  This thread had it ALL!   I wish there was some way to promote it on Google.  

The only question left in this topic is how do you size the resistor used in the voltage divider, given the fact that that beyond the voltage divider, one is using the 1.1V internal reference voltage?  Do you have to spend 3.9 volts of the HIGH digital pin on a resistor, and then any current change due to the transistor leads to the final temp?  Hopefully, someone can clarify.

Like the creator of this thread, I have searched the Internet to find this thread and I didn't find it until 5+ pages into a Google search.   If someone can give me the requested insight, I will be able to finish my design and will provide my pinout in my shared code.   In other words, a 2222 NPN transistor sensor, Arduino based 4 digit 7 segment LED thermometer ( no decimal point, as my 4 digit 7 segment devices are for clocks and have connections for colons, not decimal points).  I guess I could write it to use the bottom half of the colon and be accurate to 2 digits to the left and two digits to the right of the decimal point.  No matter what, I will write the temp measure as a subroutine and the temp display as a separate one.  That what if you have a different 4x7seg driver code you can use it instead.

One last curious question that I will experiment with with is: "What impact do connection leads to the 2222 have on the performance?"  In other words, how long a pair of wires, and of what type, can you use and still use the 2222 as a sensor.  Concept is a soil temp measure in the backyard, connected by phone line or 2 18g lines.

Thanks all!
Stephen

PS…  74HC2222 didn't bring this up but it should!  #74HC22222 #TransistorThermometer #Arduino #TransistorAsDiode
« Last Edit: April 07, 2014, 04:02:36 pm by saherr1969 » Logged

Pages: [1]   Go Up
Jump to: