I an using a Seeed Studio ESP32-C3 for a thermistor to monitor the temperature of a battery pack. The code runs however it just displays constant temps in the 130s F. Can someone out here help me figure out how to get this code to work. Thank you for any and all assistance!
/*
* FINAL CALIBRATED CODE FOR SEEED ESP32-C3
* Wiring: 3.3V -> 10k Resistor -> Pin A0 -> Thermistor -> GND
*/
const int sensorPin = 0; // A0 (GPIO 0)
const float R_FIXED = 10000.0; // 10k fixed resistor
const float R_NOMINAL = 10000.0; // 10k thermistor
const float T_NOMINAL = 25.0; // 25C
const float B_COEF = 3950.0; // Beta coefficient
void setup() {
Serial.begin(115200);
analogReadResolution(12);
analogSetAttenuation(ADC_11db);
}
void loop() {
// Take 10 readings and average them for stability
long readingSum = 0;
for (int i = 0; i < 10; i++) {
readingSum += analogRead(sensorPin);
delay(10);
}
float rawADC = readingSum / 10.0;
if (rawADC > 0 && rawADC < 4095) {
// THIS IS THE CORRECT FORMULA FOR RAW 930 -> ROOM TEMP
// Resistance = R_fixed / ( (4095 / ADC) - 1 )
float resistance = R_FIXED / ((4095.0 / rawADC) - 1.0);
// Steinhart-Hart Equation
float steinhart;
steinhart = resistance / R_NOMINAL;
steinhart = log(steinhart);
steinhart /= B_COEF;
steinhart += 1.0 / (T_NOMINAL + 273.15);
steinhart = 1.0 / steinhart;
float tempC = steinhart - 273.15;
float tempF = (tempC * 9.0 / 5.0) + 32.0;
Serial.print("Raw ADC: "); Serial.print(rawADC);
Serial.print(" | Resistance: "); Serial.print(resistance);
Serial.print(" | Temp: "); Serial.print(tempF);
Serial.println(" F");
} else {
Serial.println("Check Wiring: ADC out of range");
}
delay(1000);
}```



