#define ADC_VREF 3.3 // 3.3V
#define ADC_RESOLUTION 4095.0
#define PIN_TMP36 35 // ESP32 pin GPIO36 (ADC0) connected to LM35
void setup() {
Serial.begin(9600);
}
void loop() {
// get the ADC value from the TMP36 temperature sensor
int adcVal = analogRead(PIN_TMP36);
// convert the ADC value to voltage
float voltage = adcVal * (ADC_VREF / ADC_RESOLUTION);
// convert the voltage to the temperature in Celsius
float tempC = (voltage - 0.5) * 100;
// convert the Celsius to Fahrenheit
float tempF = tempC * 9 / 5 + 32;
// print the temperature in the Serial Monitor:
Serial.print("TMP36 Temperature: ");
Serial.print(tempC); // print the temperature in Celsius
Serial.print("°C");
Serial.print(" ~ "); // separator between Celsius and Fahrenheit
Serial.print(tempF); // print the temperature in Fahrenheit
Serial.println("°F");
delay(1000);
}