ESP32/IoT B.Tech/Diploma Beginner

Interfacing LM35 Temperature Sensor with ESP32 Web Server

Interfacing LM35 Temperature Sensor with ESP32 WiFi Microcontroller Code to read ADC temperature values & display on Web Server HTML Page

  • Suitable forB.Tech/Diploma ESP32/IoT students
  • Build time1-2 weeks
  • LevelBeginner
  • Available atAjvika Labs, Kakinada

About this project

Overview
In this project, we’ll interface an LM35 Temperature Sensor with an ESP32 to make a digital thermometer. Unlike using an Arduino and a 16*2 LCD for display, here we’ll employ the ESP32’s capability to host a web server. Earlier we used
LM35 with Arduino
to display the temperature reading on LCD screen.
The Web Server presents the temperature readings directly on a webpage which can be accessible through any standard web browser. This approach not only modernizes the display method but also enables remote temperature monitoring over a local network.
The LM35 Temperature Sensor is an analog sensor whose output is proportional to the temperature in Centigrade. It offers a temperature measurement range from -55°C to +150°C with an accuracy of +/- 0.75°C. This wide range and high accuracy make the LM35 an excellent choice for a variety of temperature-sensing applications.
Bill of Materials
We need the following components for designing a digital thermometer using LM35 Temperature Sensor & ESP32.
S.N.
Components Name
Quantity
Purchase Links
1
ESP32 Board
1
Amazon
AliExpress
2
LM35 Temperature Sensor
1
Amazon
AliExpress
3
Connecting Wires
5
Amazon
AliExpress
4
Breadboard
1
Amazon
AliExpress
LM35 Temperature Sensor
The LM35 series are precise temperature sensors with an output voltage linear to the Centigrade temperature, eliminating the need to subtract a constant voltage for Centigrade scaling unlike Kelvin-calibrated sensors. It achieves typical accuracies of ±0.25°C at room temperature and ±0.75°C across a -55°C to 150°C range without external calibration.
Its cost-effectiveness is ensured by wafer-level trimming and calibration. The LM35’s low-output impedance, linear output, and inherent calibration facilitate easy interfacing with circuitry. It operates on single or dual power supplies, drawing only 60 µA, which minimizes self-heating to under 0.1°C in still air.
Features
Calibrated directly in Degree Celsius (Centigrade)
Linear at 10.0 mV/°C scale factor
0.5°C accuracy guarantee-able (at a25°C)
Rated for full -55°C to a 150°C range.s
Suitable for remote applications
Low cost due to wafer-level trimming
Operates from 4 to 30 volts
Less than 60 mA current drain
Low self-heating, 0.08°C instill an air
Non-linearity only 0.25°C typical
Low impedance output, 0.1Ωfor 1 mA load
Working of LM35 Temperature Sensor
The LM35 temperature sensor operates based on a linear scale factor, specified as +10 millivolts (mV) per degree Centigrade. This means for every 10 mV increase in output from the sensor’s output pin (Vout), the temperature reading increases by 1°C. For instance, if the sensor outputs 100 mV at Vout, this corresponds to a temperature of 10°C. This linearity holds true for negative temperatures as well; a -100 mV output indicates -10°C.
The sensor’s functionality is derived from its internal design, featuring two transistors with a significant difference in emitter area. One transistor has ten times the emitter area of the other, resulting in a tenfold difference in current density given that the same current flows through both. This discrepancy generates a voltage across resistor R1 that is proportional to the absolute temperature, yielding an output that is nearly linear within the operational range. Any minor deviations from linearity are corrected by a special circuit that adjusts the slightly curved voltage-temperature relationship.
An amplifier in the circuit ensures the voltage at the base of one transistor (Q1) aligns with the proportional to absolute temperature (PTAT) value by comparing the outputs from the two transistors. Another amplifier then converts this PTAT voltage, representing the absolute temperature in Kelvin, into a reading in either Fahrenheit or Celsius, depending on the specific model of the sensor (LM34 for Fahrenheit, LM35 for Celsius).
Interfacing LM35 Temperature Sensor with ESP32
Let’s interface the LM35 Temperature Sensor with the ESP32 Development Board. The process for connecting the sensor is straightforward.
Connect the
VCC
of the LM35 to the
5V (Vin)
on the ESP32.
Connect the
GND
of the LM35 to a
GND
pin on the ESP32.
Finally, connect the
Vout (output)
of the LM35 to one of the ESP32’s analog input pins (e.g.,
GPIO33
)
For making the connections, a breadboard can be useful, allowing you to use jumper wires to easily connect the LM35 to the ESP32 without soldering.
Source Code/Program for Reading LM35 Temperature Value with ESP32
Let us look at the code for reading temperature readings from the LM35 Temperature Sensor using the ESP32 Board. The ESP32 uses a different approach for analog reading compared to Arduino, accounting for its 3.3V operating voltage and the capability to calibrate ADC readings for more accurate voltage measurement.
For the ESP32, the temperature calculation is slightly adapted to fit its characteristics:
Temperature (°C) = Voltage (mV) / 10
This formula is based on the LM35’s property of outputting a linear voltage increase of 10mV per degree Celsius increase in temperature. The ESP32 reads the analog value from the LM35, calibrates this reading to obtain the voltage in millivolts (using ADC calibration functions), and then divides it by 10 to convert this voltage into the corresponding temperature in Celsius.
The following code reads temperature data from an LM35 sensor connected to an ESP32 and calculates the temperature in both Celsius and Fahrenheit. It then prints these temperature readings to the Serial Monitor every second, allowing for real-time monitoring of the sensor’s output.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include \"esp_adc_cal.h\"
// Define the GPIO pin where the LM35 temperature sensor is connected
#define LM35_SENSOR_PIN 33
// Function prototype for reading and calibrating the ADC value
uint32_t
readAndCalibrateADC
(
int
rawADCValue
)
;
void
setup
(
)
{
// Initialize serial communication at 115200 baud to print the temperature readings
Serial
begin
(
115200
)
;
}
void
loop
(
)
{
// Variables to store raw ADC value, voltage in millivolts, and temperatures in Celsius and Fahrenheit
int
rawADCValue
=
0
;
float
voltageInMilliVolts
=
0.0
;
float
temperatureInCelsius
=
0.0
;
float
temperatureInFahrenheit
=
0.0
;
// Read the raw ADC value from the LM35 sensor
rawADCValue
=
analogRead
(
LM35_SENSOR_PIN
)
;
// Calibrate the raw ADC value and convert it to voltage in millivolts
voltageInMilliVolts
=
readAndCalibrateADC
(
rawADCValue
)
;
// Calculate the temperature in Celsius. The LM35 outputs 10mV per degree Celsius.
temperatureInCelsius
=
voltageInMilliVolts
/
10
;
// Convert the temperature to Fahrenheit
temperatureInFahrenheit
=
(
temperatureInCelsius *
1.8
)
+
32
;
// Print the temperature readings in both Celsius and Fahrenheit
Serial
(
\"Temperature = \"
)
;
Serial
(
temperatureInCelsius
)
;
Serial
(
\" °C, \"
)
;
Serial
(
\"Temperature = \"
)
;
Serial
(
temperatureInFahrenheit
)
;
Serial
println
(
\" °F\"
)
;
// Delay for a short period before reading the temperature again
delay
(
1000
)
;
// Delay of 1 second
}
// Function to read and calibrate the raw ADC value to voltage in millivolts
uint32_t
readAndCalibrateADC
(
int
rawADCValue
)
{
// ADC calibration characteristics
esp_adc_cal_characteristics_t
adcCharacteristics
;
// Characterize the ADC at attenuation of 11dB and width of 12 bits
esp_adc_cal_characterize
(
ADC_UNIT_1
ADC_ATTEN_DB_11
ADC_WIDTH_BIT_12
1100
&
adcCharacteristics
)
;
// Convert the raw ADC value to calibrated voltage in millivolts
return
esp_adc_cal_raw_to_voltage
(
rawADCValue
&
adcCharacteristics
)
;
}
Upload the code to the ESP32 Board. Then open the Serial Monitor after uploading is completed.
The Serial Monitor will show the value of temperature reading in both Celsius and Fahrenheit

Technologies used

ESP32ArduinoBLELCDADC

Hardware components

  • ESP32
  • Arduino
  • LM35

Software & tools

  • Arduino IDE

What you get

  • Working project / hardware kit, tested before delivery
  • Complete source code with explanation
  • Project demo and guidance for your viva
  • Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed. Payment is in two parts: • 50% advance to start the project • Remaining 50% before delivery Note: • Documentation and PPT are not included by default • If you need documentation/PPT, it can be arranged for extra time and cost We'll confirm the exact timeline and cost with you after reviewing your requirements.