#include <LiquidCrystal_I2C.h>
#define THERMISTOR_COUNT 10
const int THERMISTOR_PINS[THERMISTOR_COUNT] = {34, 35, 32, 33, 25, 26, 27, 14, 12, 13};
double Rth_values[THERMISTOR_COUNT];
double temperature_values[THERMISTOR_COUNT];
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;
void setup() {
Serial.begin(9600); /* Define baud rate for serial communication */
lcd.begin(16, 2);
lcd.print("Temperature:");
}
void loop() {
for (int i = 0; i < THERMISTOR_COUNT; i++) {
double Vout, Rth, temperature, adc_value;
adc_value = adc_resolution - analogRead(THERMISTOR_PINS[i]) + 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
/* Steinhart-Hart Thermistor Equation:
* Temperature in Kelvin = 1 / (A + B[ln(R)] + C[ln(R)]^3)
*/
temperature = 1 / (A + (B * log(Rth)) + (C * pow(log(Rth), 3))); // Temperature in kelvin
temperature = temperature - 273.15; // Temperature in degree Celsius
Rth_values[i] = Rth;
temperature_values[i] = temperature;
lcd.setCursor(0, i);
lcd.print("Thermistor ");
lcd.print(i + 1);
lcd.print(": ");
lcd.print(temperature_values[i]);
lcd.print(" C ");
Serial.print("Thermistor ");
Serial.print(i + 1);
Serial.print(": Rth = ");
Serial.print(Rth_values[i]);
Serial.print(", Temperature = ");
Serial.print(temperature_values[i]);
Serial.println(" degree Celsius");
}
delay(50000);
}