// With the AD 595, this process is just a matter of doing some math on an // analog input // // Thanks to Karl Gruenewald for the conversion formula // All code released under // Creative Commons Attribution-Noncommercial-Share Alike 3.0 // This current version is based on sensing temperature with // an AD595 and thermocouple through an A/D pin. Any other // sensor could be used by replacing this one function. // feel free to use degrees C as well, it will just give a different // PID tuning than those from F. // #define TEMP_SENSOR_PIN 1 #define AVERAGE_COUNT 1000 // this will essentially control the update speed float tcSum = 0.0; float latestReading = 0.0; int readCount = 0; float multiplier; void setupTempSensor() { multiplier = 1.0/(AVERAGE_COUNT * 1023.0) * 500.0 * 9.0 / 5.0; } void updateTempSensor() { if (readCount < AVERAGE_COUNT) { tcSum += analogRead(TEMP_SENSOR_PIN); //output from AD595 to analog pin 1 readCount +=1; } else { latestReading = tcSum* multiplier+32.0; readCount = 0; tcSum = 0.0; } } float readTempF() { return latestReading; } // END Temperature Sensor