// Reference https://docs.wokwi.com/parts/wokwi-ntc-temperature-sensor
#define sensorPin A0
#define BETA 3950
int ledArray[] = {4,5,6,7,8,9,10,11,12,13};
void setup() {
// initialize LEDs as outputs
for (int i = 0; i < 10; i++) {
pinMode(ledArray[i], OUTPUT);
}
}
void loop() {
// Read the raw analog value from the NTC sensor
int analogValue = analogRead(sensorPin);
// Calculate temperature in Celsius using Beta parameter equation
float celsius = 1.0 / (log(1.0 / (1023.0 / analogValue - 1.0)) / BETA + 1.0 / 298.15) - 273.15;
// Map the temperature range (-24°C to 80°C) to 0-10 active LEDs
int ledsToLight = map(celsius, -24, 80, 0, 10);
ledsToLight = constrain(ledsToLight, 0, 10);
// Light up the corresponding number of LEDs
for (int i = 0; i < 10; i++) {
if (i < ledsToLight) {
digitalWrite(ledArray[i], HIGH);
} else {
digitalWrite(ledArray[i], LOW);
}
}
delay(10); // this speeds up the simulation
}