,

LM35 temperature sensor with ESP32

Posted by

Let me introduce you to the LM35 temperature sensor with ESP32. It is an integrated calibrated temperature sensor that offers an output of 10mV/ºC. All of that in the range of -55 to +150ºC; you can find its datasheet here.

Mechanically it is housed in a TO-92 case, not really very useful when one needs contact measurements. But a nice case for when one needs to measure “free air” on a circuit board and the likes.

A LM35 temperature sensor. Source: https://www.amazon.com.br/Sensor-Temperatura-Lm35-C%C3%B3digo-Arduino/dp/B07GHZPS5W
A LM35 temperature sensor. Source: https://www.amazon.com.br/Sensor-Temperatura-Lm35-C%C3%B3digo-Arduino/dp/B07GHZPS5W

As stated above, its sensitivity is 10mV per degree Celsius, meaning it will output (for example) 250mV @ 25 degrees Celsius.

The assembly

Below you can see the schematic diagram for our test. Notice how simple it is, just the LM35 connected to the ESP32-C6 development board.

LM35 and ESP32-C6 schematic diagram
LM35 and ESP32-C6 schematic diagram

Then the assembly on a breadboard is seen below, notice how diminute the sensor is.

LM35 temperature sensor with ESP32
LM35 temperature sensor (TO-92) with ESP32
lm35 on a breadboard
LM35 temperature sensor (TO-92) on a breadboard

Code and testing

The code below was written by myself, no help and no copying from the internet. It is simple enough, all you do is read the analog channel A1 and divide the result by ten. This allow the value in milivolts to be converted to degrees Celsius.

Then I present it on the Arduino IDE serial monitor, via Serial.print() to be seen on your computer screen.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  int analogVolts = analogReadMilliVolts(A1);
  long temperature = analogVolts / 10.0;
  Serial.print("temperature= ");
  Serial.print(temperature);
  Serial.println(" oC");
  delay(2000);
}

Results can be seen in the neat video below, where I explain everything I have written above. Enjoy!

Final words

LM35 is a cheap little temperature sensor, which is factory-calibrated and very precise. It can be used to read temperatures in “free air” while soldered to a print circuit board.

Do you want to know more temperature sensors? read this article about NTC thermistors.

Leave a Reply

Your email address will not be published. Required fields are marked *