// Define the pin for the LED
const int ledPin = 13; // Use built-in LED pin on Arduino Uno
// Define the pin for the NTC thermistor
const int thermistorPin = A0; // Analog input pin A0
// Variables for the thermistor and calculated temperature
int thermistorValue; // Raw ADC value from thermistor
float temperature; // Calculated temperature in degrees Celsius
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // Initialize serial communication at 9600 baud
}
void loop() {
// Read the raw ADC value from the thermistor
thermistorValue = analogRead(thermistorPin);
// Convert the ADC value to resistance (using a voltage divider formula)
float resistance = 10000.0 / (1023.0 / thermistorValue - 1);
// Steinhart-Hart equation to calculate temperature in Celsius
float steinhart;
steinhart = resistance / 10000; // (R/Ro)
steinhart = log(steinhart); // ln(R/Ro)
steinhart /= 3950; // 1/B * ln(R/Ro)
steinhart += 1.0 / (25 + 273.15); // + (1/To)
steinhart = 1.0 / steinhart - 273.15; // Invert Steinhart
// Print temperature to serial monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
// Blink LED based on temperature
if (temperature < 25.0) {
digitalWrite(ledPin, HIGH); // Turn LED on
delay(500); // Wait for 500 milliseconds
digitalWrite(ledPin, LOW); // Turn LED off
delay(500); // Wait for 500 milliseconds
} else {
digitalWrite(ledPin, LOW); // Keep LED off
delay(1000); // Wait for 1 second
}
}