Permalink
Browse files

updated to match tutorial

  • Loading branch information...
1 parent a52361e commit 44552d698ffabc81ced09579a1bd5f1bea519382 @ladyada ladyada committed Jun 7, 2011
Showing with 9 additions and 8 deletions.
  1. +9 −8 thermistortest.pde
View
@@ -1,4 +1,3 @@
-
// which analog pin to connect
#define THERMISTORPIN A0
// resistance at 25 degrees C
@@ -17,30 +16,32 @@ int samples[NUMSAMPLES];
void setup(void) {
Serial.begin(9600);
+ 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++) {
+ for (i=0; i< NUMSAMPLES; i++) {
average += samples[i];
- }
- average /= NUMSAMPLES;
+ }
+ average /= NUMSAMPLES;
Serial.print("Average analog reading ");
Serial.println(average);
+
// convert the value to resistance
- average = 1023 / average;
- average *= SERIESRESISTOR;
- average -= SERIESRESISTOR;
+ average = 1023 / average - 1;
+ average = SERIESRESISTOR / average;
Serial.print("Thermistor resistance ");
Serial.println(average);

0 comments on commit 44552d6

Please sign in to comment.