// Define LED pins
const int ledPins[10] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
// Define sensor pin
const int sensorPin = A0;
// Define Beta Coefficient for the thermistor
const float BETA = 3950;
void setup() {
// Initialize the LED pins as outputs
for (int i = 0; i < 10; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
int analogValue = analogRead(sensorPin);
// Calculate the temperature in Celsius using the provided formula
float celsius = 1 / (log(1 / (1023.0 / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
// Map temperature to a range of 0 to 10 (LED levels)
int ledLevel = map(celsius, -24, 80, 0, 10);
// Constrain LED level to be within 0 to 10
ledLevel = constrain(ledLevel, 0, 10);
// Update LED display
for (int i = 0; i < 10; i++) {
if (i < ledLevel) {
digitalWrite(ledPins[i], HIGH);
} else {
digitalWrite(ledPins[i], LOW);
}
}
delay(500);
}