/*
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/tutorials/arduino-lm35-temperature-sensor
*/
void setup() {
pinMode(8, OUTPUT);
pinMode(A0, INPUT);
Serial.begin(9600);
}
void loop() {
// get the ADC value from the temperature sensor
int p = analogRead(A0);
// convert the ADC value to voltage in millivolt
float milliVolt = p* (4.88);
// convert the voltage to the temperature in Celsius
float tempC = milliVolt / 10;
// convert the Celsius to Fahrenheit
float tempF = tempC * 9 / 5 + 32;
if(tempC<25)
digitalWrite(8, LOW);
else
digitalWrite(8, HIGH);
// print the temperature in the Serial Monitor:
Serial.print("Temperature: ");
Serial.print(tempC); // print the temperature in Celsius
Serial.print("°C");
Serial.print(" ~ "); // separator between Celsius and Fahrenheit
Serial.print(tempF); // print the temperature in Fahrenheit
Serial.println("°F");
delay(1000);
}