/* Example program to measure the response time of the thermistor temperature sensor. Written by: Pat Arnott, for ATMS 360. Use the circuit for the photoresistor in Experiment 6 of the USK Guide, but replace the photoresistor with the thermistor. The thermistor resistance is measured indirectly with a voltage divider. +5v ------/\/\/\-------------/\/\/\------- gnd 10,000 Ohms Thermistor Vout ***** Note that the fixed resistance value can be changed to optimize response. Vout is measured between the fixed resistor of 10,000 Ohms (10 kOhm) and thermistor. Place an LED and 330 ohm resistor in pin 13 of the Arduino. When the LED is lit, pinch the sensor to warm it up. Release when the sensor goes out. You can also just look at the LED by pin 13 on the Arduino board. It also lights when pin 13 is used. You may modify this code to better present your results. The thermistor used: Gikfun 100K ohm NTC B4267 ATC Semitic 104GT-2 Thermistor for 3D Printer Reprap EK9018. */ // Global variable definitions. // Note these are the pins to connect on the Arduino. int ledPin = 13; int sensorPin = A0; // Analog input pin for the thermistor voltage. float sensorValue = 0.0; // Variable to store the measurement from the sensor. int i ; // variable in for loop. float TC; // Calculated temperature value in Celcius. int iMeas = 300 ; // Number of measurements to do before, during, and after pinching the Thermistor. float Rfixed=10.0 ; // Resistance in kOhms of the fixed resistor used in the voltage divider. Change this value if working with other resistors. // We put out setup code here, to run only once at the start: void setup() { pinMode(ledPin, OUTPUT); Serial.begin(230400) ; // Sets the serial port to 230400 bits per second transfer. } // We put our main code here, to run repeatedly: void loop() { for (int j=0 ; j <=1; j++) { digitalWrite(ledPin, j); // This turns the LED off or on when j=0 or 1. for (i=0 ; i < iMeas; i++) { sensorValue = 0.0 ; // Average 500 measurements // int start = millis() ; for (int k=0 ; k < 500; k++) { // Loop to average 500 measurements. sensorValue = analogRead(sensorPin) + sensorValue ; // Converts to voltage. } sensorValue=sensorValue*0.00488759/500.0 ; // Serial.println(millis()-start) ; TC = get_T_From_V() ; // Converts voltage to temperature. Serial.print(millis()) ; Serial.print(",") ; // comment out this line if you want to graph. Serial.println(TC) ; } // loop over i, the sensor measurements. } // loop over j, turning the LED first off, then on. } /* Function to calculate the thermistor temperature from the voltage divider measurement of thermistor resistance. RT is the thermistor resistance calculated from the voltage divider. Rfixed is the fixed value of resistance. 5.0 is the voltage of the Arduino power supply. Thermistor model: Gikfun 100K ohm NTC B4267 ATC Semitic 104GT-2 Thermistor for 3D Printer Reprap EK9018. */ float get_T_From_V() { // Calculate thermistor temperature from voltage. float Ttherm ; // Thermistor temperature calculated here. float RT ; // Resistance of the thermistor. float logRT ; // Natural log of RT, used in temperature calculation. float aa=7.58546e-4 ; // thermistor calculation constant a from table. float bb=2.18117e-4 ; // thermistor calculation constant b from table. float dd=5.53062e-8 ; // thermistor calculation constant d from table. RT = Rfixed * sensorValue / (5.0-sensorValue) ; // Thermistor resistance in kOhms. logRT = log(RT) + 6.907755279 ; // The second term comes from conversion to Ohms Ttherm = aa + bb*logRT + dd*logRT*logRT*logRT ; Ttherm = 1.0/Ttherm - 273.15 ; // Thermistor temperature in Celcius. return Ttherm ; }