So now we combine the two (Vo = Vi) and get:
ADC value = R / (R + 10K) * Vcc * 1023 / Vcc
What is nice is that if you notice, the Vcc value cancels out!
ADC value = R / (R + 10K) * 1023
It doesn't matter what voltage you're running under. Handy!
Finally, what we really want to do is get that R (the unknown resistance). So we do a little math
to move the R to one side:
R = 10K / (1023/ADC - 1)
Great, lets try it out. Connect up the thermistor as shown:
Connect one end of the 10K resistor to 5V, connect the other end of the 10K 1% resistor to
one pin of the thermistor and the other pin of the thermistor to ground. Then connect Analog 0
pin to the 'center' of the two.
Now run the following sketch:
// the value of the 'other' resistor
#define SERIESRESISTOR 10000
// What pin to connect the sensor to
#define THERMISTORPIN A0
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
float reading;
reading = analogRead(THERMISTORPIN);
Serial.print("Analog reading ");
© Adafruit
Industries
http://learn.adafruit.com/thermistor Page 7 of 13
You should get responses that correspond to the resistance of the thermistor as measured
with a multimeter
Better Readings
When doing analog readings, especially with a 'noisy' board like the arduino, we suggest two
tricks to improve results. One is to use the 3.3V voltage pin as an analog reference and the
other is to take a bunch of readings in a row and average them.
The first trick relies on the fact that the 5V power supply that comes straight from your
computer's USB does a lot of stuff on the Arduino, and is almost always much noisier than the
3.3V line (which goes through a secondary filter/regulator stage!) It's easy to use, simply
connect 3.3V to AREF and use that as the VCC voltage. Because our calcuations don't include
the VCC voltage, you don't have to change your equation. You do have to set the analog
reference but that's a single line of code
Taking multiple readings to average out the result helps get slightly better results as well, since
you may have noise or fluctuations, we suggest about 5 samples.
Rewire as shown:
This sketch takes those two improvements and integrates them into the demo, you will have
better, more precise readings.
Serial.print("Analog reading ");
Serial.println(reading);
// convert the value to resistance
reading = (1023 / reading) - 1;
reading = SERIESRESISTOR / reading;
Serial.print("Thermistor resistance ");
Serial.println(reading);
delay(1000);
}
// which analog pin to connect
#define THERMISTORPIN A0
// how many samples to take and average, more takes longer
© Adafruit
Industries
http://learn.adafruit.com/thermistor Page 8 of 13
Converting to Temperature
Finally, of course, we want to have the temperature reading, not just a resistance! If you just
need to do a quick comparision circuit (if temperature is below X do this, if its above Y do that),
you can simply use the temperature/resistance table which correlates the resistance of the
thermistor to the temperature.
However, you probably want actual temperature values. To do that we'll use the Steinhart-Hart
equation (http://adafru.it/aK5) , which lets us do a good approximation of converting values. Its
not as exact as the thermistor table (it is an approximation) but its pretty good around the
temperatures that this thermistor is used.
// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 5
// the value of the 'other' resistor
#define SERIESRESISTOR 10000
int samples[NUMSAMPLES];
void setup(void) {
Serial.begin(9600);
// connect AREF to 3.3V and use that as VCC, less noisy!
analogReference(EXTERNAL);
}
void loop(void) {
uint8_t i;
float average;
// take N samples in a row, with a slight delay
for (i=0; i< NUMSAMPLES; i++) {
samples[i] = analogRead(THERMISTORPIN);
delay(10);
}
// average all the samples out
average = 0;
for (i=0; i< NUMSAMPLES; i++) {
average += samples[i];
}
average /= NUMSAMPLES;
Serial.print("Average analog reading ");
Serial.println(average);
// convert the value to resistance
average = 1023 / average - 1;
average = SERIESRESISTOR / average;
Serial.print("Thermistor resistance ");
Serial.println(average);
delay(1000);
}
© Adafruit
Industries
http://learn.adafruit.com/thermistor Page 9 of 13

372

Mfr. #:
Manufacturer:
Keystone Electronics
Description:
Standoffs & Spacers 1.5 Rnd Clr Hle Spcr .250 OD #6 Phenolic
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union

Products related to this Datasheet