I'm trying to print ina oled display the temperature value obtained by a LM35 connected to an analog port on an ESP32 Devboard.
I have connected an DHT11 sensor to make a comparison with the value measured by the LM35 and unfortunately those values are wrong despite the voltage in LM35 is correct (stable in a room temperature and increase with the heat of my finger). The resolution in 10mV/ºC, thus, the respective values found were 250 mV and 360 mV respectively.
The LM35 is charged with 5V (minimum value)and the analog reference tension in ESP32 is 3.3V.
In this case, what is the right way to read the values. Is there something related with the analogReference?
I would venture to say that the LM35 is the wrong thing to use with a ESP32 unless some adjustments are made. If one was to look at a LM35 data sheet one would find that the input voltage is from 4V <<<<
One would find the output voltage to be between -1 to 6 V <<<<
The ESP32 is a 3.3V device. The output of the LM35 can exceed the 3.3V limits of the ESP32.
void loop() {
// get the ADC value from the temperature sensor
int adcVal = analogRead(PIN_LM35);
// convert the ADC value to voltage in millivolt
float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
// convert the voltage to the temperature in Celsius
float tempC = milliVolt / 10;
// convert the Celsius to Fahrenheit
float tempF = tempC * 9 / 5 + 32;
// print the temperature in the Serial Monitor:
Serial.print("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");