// Analog input pin for the NTC thermistor
const int NTC_PIN = 13;
// Temperature threshold to trigger the alarm (adjust as needed)
const float TEMPERATURE_THRESHOLD = 30.0;
void setup() {
Serial.begin(115200);
pinMode(NTC_PIN, INPUT);
}
void loop() {
int rawValue = analogRead(NTC_PIN);
float voltage = (rawValue / 4095.0) * 3.3; // Assuming ESP32 ADC has a 12-bit resolution (4096 levels) and operates at 3.3V
// Calculate resistance of NTC thermistor using voltage divider formula
float resistance = (3.3 * 10000) / voltage - 10000;
// Assuming a 10KΩ NTC thermistor, use Steinhart-Hart equation to calculate temperature
float A = 0.003354016; // Steinhart-Hart coefficients
float B = 0.000256985;
float C = 0.000002620131;
float tempK = 1 / (A + B * log(resistance) + C * pow(log(resistance), 3));
float tempC = tempK - 273.15;
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.println("C");
if (tempC > TEMPERATURE_THRESHOLD) {
// Alarm condition
// You can add code here to trigger an external alarm or take other actions
}
delay(1000); // Wait for 1 second before updating temperature
}