#include <math.h> // For the log() function
const float BETA = 3950; // Beta coefficient of the thermistor (from datasheet)
const int analogPin = 34; // ESP32 ADC pin (use GPIO 34 or other ADC-capable pins)
void setup() {
Serial.begin(115200); // Start serial monitor at 115200 baud
}
void loop() {
// Read the analog value (0-4095 range for ESP32)
int analogValue = analogRead(analogPin);
// Temperature calculation (adjusted for ESP32 ADC range)
float celsius = 1 / (log(1 / (4095.0 / analogValue - 1)) / BETA
+ 1.0 / 298.15) - 273.15;
// Output temperature to the serial monitor
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
delay(1000); // Wait 1 second before reading again
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
ntc1:GND
ntc1:VCC
ntc1:OUT