// Author: Ari Vuokila // Modified by Kati Pitkänen on April 30, 2018 // Week 12 - Input Devices #include int tempPin = A0; // Selects the input pin for the temperature sensor // INPUT int Temperature; // Initialization of the variable ‘Temperature’ float sensorValue; // Define the variable to store the sensor value data void setup() { // Start this function will after setup finishes and then repeat. Serial.begin(9600); pinMode(tempPin, INPUT); // Temperature sensor is in input pin PC0 } void loop() { // Run over and over again //Arduino converts an analog voltage input (0 - 5V) on tempPin to digital value (0 - 1023) = changes the values from 0-5 to a range 0-1023 that corresponds to the voltage the pin is reading sensorValue = analogRead(tempPin); // Read and store the analog input value coming from the temp sensor pin double Temp, T; // Define the variables to show the temperature data double R = 10000 / (1023.0 / sensorValue - 1); // Steinhart - Hart /// Resistance = 10 k ohm /// (2^10 = 1024) double L = 10000 / R; // L = R0/R // 10000/R = ReferenceResistance/ NominalResistance = ResistanceInNominalTemperature25oC) //T = 1.0/((1.0/(25.0 + 273.15)) + (log(R0/R))/3750)) //T = 1.0/((1.0/(25.0 + 273.15)) + (log(L))/3750) * log(L)) T = (0.0033540164 + 0.00026666666 * log(L)); // Steinhart-Hart 1/T=1/T0 + 1/B*ln(R0/R) T = 1/T; Temp = T - 273.15; // To get Celcius degrees Temperature = T - 273.15 (Kelvin degrees) Serial.print("Temperature "); // To print information to the Serial Monitor Serial.print(Temp); Serial.println(" C "); delay(500); }