// These constants won't change. They're used to give names // to the pins used: const int analogInPin = 1; // Analog input pin that the potentiometer is attached to int i = 0; int sample = 30; float rawArray[30]; float raw; float averageRaw; float sumRaw; float referenceVoltage; float volts; float voltDivisor; float millivolts; float kelvin; float celcius; void setup() { Serial.begin(57600); //arduino duemilanove atmega328 4.98v referenceVoltage = 4980; } void loop() { raw = analogRead(analogInPin); rawArray[i] = raw; for (int i = 0; i < 30; i++) sumRaw = sumRaw + rawArray[i]; averageRaw = sumRaw/sample; //Arduino analogReads in a value 0-1024 voltDivisor = 1024/referenceVoltage; millivolts = averageRaw/voltDivisor; kelvin = millivolts/10; volts = millivolts / 1000; celcius = kelvin - 273.15; clrScr(); Serial.print("averaged="); Serial.print(celcius); Serial.print("C"); // voltage divisor = 1024/5v = 204.8 millivolts = raw/voltDivisor; kelvin = millivolts/10; // convert to kelvin: [°C] = [K] − 273.15 celcius = kelvin - 273.15; Serial.print(" instantTemp="); Serial.print(celcius); Serial.print("C"); Serial.println(""); Serial.print("kelvin="); Serial.print(kelvin); Serial.print("K"); Serial.println(""); Serial.print("v="); Serial.print(volts); Serial.print(" mV="); Serial.print(millivolts); Serial.println(""); Serial.print("analog");Serial.print(analogInPin);Serial.print(":"); Serial.print(raw); i++; if (i >= sample) { i = 0; } sumRaw = 0; // wait n milliseconds before the next loop // for the analog-to-digital converter to settle after the last reading: int n = 200; delay(n); } /////////////////////////////// // Tellymate functions /////////////////////////////// void clrScr(){ #define CHAR_ESC '\x1B' Serial.print( CHAR_ESC ) ; Serial.print( 'E' ) ; // clear screen }