//Pin configuration
const int analogPin = 33; // esp32 pin where thermistor is connected

const float nominalResistance = 10000; // resistance of thermistor at 25c (in ohms)
const float nominalTemperature = 25; // temperature for normal resistance in °C
const float bCoefficient = 3950; // beta coeffiecient provuded by the thermistors datasheet
const float seriesResistor = 10000; // value of the series resistor in ohms

float vref = 3.3;    //esp32 reference voltage

int adcMaxValue = 4095; //12 bit adc (value from 0 to 4095)

void setup(){
  Serial.begin(115200); // initialize serial monitor at 115200 baud

}

void loop(){

  // read the analog input
  int analogValue = analogRead(analogPin);
  /// convert the adc value to the voltage
  float voltage = analogValue * (vref / adcMaxValue);
  // calculate the thermistor resistance
  float thermistorResistance = (seriesResistor * (vref / voltage)) - seriesResistor;

  float steinhart;
  steinhart = thermistorResistance / nominalResistance;
  steinhart = log(steinhart);
  steinhart /= bCoefficient;
  steinhart += 1.0 / (nominalTemperature + 273.15);
  steinhart = 1.0 / steinhart;
  steinhart -= 237.15;

  Serial.print("Temperature: ");
  Serial.print(steinhart);
  Serial.println(" °C");

  delay(1000);
}