// https://wokwi.com/projects/359721102307523585
// for https://forum.arduino.cc/t/thermistor-output-connected-to-nodemcu-esp32/1074739
#define THERMISTORPIN 34
const double VCC = 3.3; // NodeMCU on board 3.3v vcc
const double R2 = 10000; // 10k ohm series resistor
const double adc_resolution = 4096; // 12-bit adc
const double A = 0.001129148; // thermistor equation parameters
const double B = 0.000234125;
const double C = 0.0000000876741;
int ledPins[] = {
32,33,25,26,27,14,12,13,2,4
};
int ledCount = 10;
void setup() {
Serial.begin(9600);
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}
void loop() {
double Vout, Rth, kelvin, tempC, tempF, adc_value;
adc_value = adc_resolution-analogRead(THERMISTORPIN)+0.5; // switch direction
Vout = (adc_value * VCC) / adc_resolution;
Rth = (VCC * R2 / Vout) - R2; // Formula for R2 as Pull-down: Vcc-Rth-R2-GND
kelvin = (1 / (A + (B * log(Rth)) + (C * pow((log(Rth)),3)))); // Temperature in kelvin
tempC = kelvin - 273.15;
tempF = (tempC * 9/5) +32;
int tempFMap = map(tempF*100, 1394, 17540, 0,10);
for(int i = 0; i <= tempFMap; i++){
digitalWrite(ledPins[ledCount-1-i], LOW);
}
// switch(tempFMap){
// case: 1
// }
Serial.print("Rth:");
Serial.print(Rth);
Serial.print(" Temperature = ");
Serial.print(tempC);
Serial.println(" degree celsius or ");
Serial.print(tempF);
Serial.println(" degree fareinghit");
delay(500);
clearDisplay();
}
void clearDisplay(){
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
digitalWrite(ledPins[ledCount-1-thisLed], HIGH);
}
}