const int sensorPin = A0;
const byte ledPins[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
const int numLEDs = 10;
void setup() {
for (byte i = 0; i < numLEDs; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
int analogValue = analogRead(sensorPin);
float temperature = convertToCelsius(analogValue);
int ledCount = map(temperature, -24, 80, 0, numLEDs);
ledCount = constrain(ledCount, 0, numLEDs);
for (byte i = 0; i < numLEDs; i++) {
if (i < ledCount) {
digitalWrite(ledPins[i], LOW);
} else {
digitalWrite(ledPins[i], HIGH);
}
}
delay(1000);
}
float convertToCelsius(int analogValue) {
const float BETA = 3950.0;
float resistance = (1023.0 / analogValue) - 1.0;
resistance = 10000.0 * resistance;
float temperature = 1.0 / (log(resistance / 10000.0) / BETA + 1.0 / 298.15) - 273.15;
return temperature;
}