// 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};
const int numLeds = 10;
void setup() {
// initialize LEDs and sensor pin
for (int i=0; i < numLeds; i++){
pinMode(ledArray[i], OUTPUT);
}
pinMode(sensorPin, INPUT);
analogReadResolution(12);
}
void loop() {
// Read the sensor value , calculate the temperature, light up the leds
int analogValue = analogRead(sensorPin);
float celsius = 1 / (log(1 / (4095. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
int litCount = map(constrain(celsius, -24, 80), -24, 80, 0, numLeds);
for(int i = 0; i < numLeds; i++){
digitalWrite(ledArray[i], i < litCount ? HIGH : LOW);
}
}
delay(10); // this speeds up the simulation