#include <math.h>
const int pinNTC = 3; // pin ADC1
const float R_FIJA = 10000.0; // resistencia fija en ohms (ajusta según tu circuito)
const float BETA = 3950.0; // coeficiente Beta del NTC (revisa datasheet)
const float R0 = 10000.0; // resistencia nominal del NTC a T0
const float T0 = 298.15; // T0 en Kelvin (25°C)
void setup() {
Serial.begin(115200);
}
void loop() {
int lectura = analogRead(pinNTC);
float voltaje = lectura * (3.3 / 4095.0);
// Voltaje a resistencia (NTC conectado a GND, R fija arriba)
float resistenciaNTC = R_FIJA * (3.3 / voltaje - 1.0);
// Resistencia a temperatura (ecuación Beta)
float tempK = 1.0 / (1.0/T0 + (1.0/BETA) * log(resistenciaNTC / R0));
float tempC = tempK - 273.15;
Serial.print("Voltaje: ");
Serial.print(voltaje, 3);
Serial.print(" V | R_NTC: ");
Serial.print(resistenciaNTC, 0);
Serial.print(" ohms | Temp: ");
Serial.print(tempC, 2);
Serial.println(" °C");
delay(500);
}