// which analog pin to connect #define THERMISTORPIN A1 // resistance at 25 degrees C #define THERMISTORNOMINAL 10000 // temp. for nominal resistance (almost always 25 C) #define TEMPERATURENOMINAL 25 // how many samples to take and average, more takes longer // but is more 'smooth' #define NUMSAMPLES 5 // The beta coefficient of the thermistor (usually 3000-4000) #define BCOEFFICIENT 3950 // the value of the 'other' resistor #define SERIESRESISTOR 10000 // the calibrated temperature taken from calibration sketch #define CALIBRATED_TEMP 53 int samples[NUMSAMPLES]; int outPin0 = 0; // pin #5 red LED void setup(void) { pinMode(outPin0, OUTPUT); } 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; // convert the value to resistance average = 1023 / average - 1; average = SERIESRESISTOR / average; float calcnum; calcnum = average / THERMISTORNOMINAL; // (R/Ro) calcnum = log(calcnum); // ln(R/Ro) calcnum /= BCOEFFICIENT; // 1/B * ln(R/Ro) calcnum += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To) calcnum = 1.0 / calcnum; // Invert calcnum -= 273.15; // convert to C float calcnumF; calcnumF = (9 / 5) * calcnum + 32; /* add or subtract the temperature you are monitoring starting * with CALIBRATED_TEMP. If you want to monitor + 5 degrees, * add 5 to CALIBRATED_TEMP, if you want to monitor - 5 degrees, * subtract 5 from CALIBRATED_TEMP * Note also that if you want to measure a lower temperature, * you need to change the greater than sign (>) to a less than * sign (<) * If you use an incremented value of only one or two, you * may find that the calibration has changed due to an increase * in room temperature. Then the red LED will flash at two * or three points above your calibrated temperature. Don't * be surprised if this happens. */ if (calcnumF > CALIBRATED_TEMP + 3) { // red LED blinks analogWrite(outPin0, 255); delay(25); analogWrite(outPin0, 0); delay(50); } }