prototype number 1 |
[ADC stands for Analog to Digital Converter]
Therefore we have to use a formula. Since we know the total Voltage,(Vt), (ADC total) = 1024, and (ADC calculated) which is the reading provided in analog A0. We can find the numerical calculated voltage reading.
As the temperature sensor has a breakdown voltage directly proportional to absolute temperature at +10mV/K, with the voltage reading, we can find out the temperature in Kelvin.
Converting from Kelvin to Celsius, we need to minus 273.15
Hence the code we uploaded into the Arduino software to calculate this reading is as shown below;
float tempK=0, tempC=0, tempF=0;
void setup(){
Serial.begin(9600); //Setup serial to 9600 bps
}
void loop(){
float reading = analogRead(A0) * 5.0; //Where 5V and the Analog (ADC) input
reading /= 1024.0; // is used to determine the voltage reading
tempK = reading * 100; //Read temperature in Kelvins first
tempC = tempK - 273.15; //Convert from Kelvin to Celsius
tempF = ((tempK) * 9 / 5) - 459.67; //Convert from Kelvin to Fahrenheit
//Print all the values to Serial
Serial.print("Voltage: "); //Print the reading of the voltage
Serial.println(reading); //on Serial Monitor
Serial.println();
Serial.print("Kelvin: "); //Print the reading of the temperature
Serial.println(tempK); //in Kelvin on Serial Monitor
Serial.print("Celsius: "); //Print the reading of the temperature
Serial.println(tempC); //in Celsius on Serial Monitor
Serial.print("Fahrenheit: "); //Print the reading of the temperature
Serial.println(tempF); //in Fahrenheit on Serial Monitor
Serial.println(); //Print Blank Line
delay(3000); //Delay 1.5 second
}
No comments:
Post a Comment