// 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 and sensor pin
for (int i = 0; i < 10; i++) {
pinMode(ledArray[i], OUTPUT);
}
}
void loop() {
// Read the sensor value , calculate the temperature, light up the leds
int analogValue = analogRead(sensorPin);
int temperature = map(analogValue, 0, 1023, -24, 80);
int ledCount = map(temperature, -24, 80, 0, 10);
ledCount = constrain(ledCount, 0, 10);
for (int i = 0; i < 10; i++) {
digitalWrite(ledArray[i], (i < ledCount) ? HIGH : LOW);
}
delay(10);// this speeds up the simulation
}