LM35 Interfacing with NodeMCU

Overview of LM35

LM35 temperature sensor
LM35 temperature sensor

 

LM35 is a temperature sensor that can measure temperature in the range of -55°C to 150°C.

It is a 3-terminal device that provides an analog voltage proportional to the temperature. The higher the temperature, the higher is the output voltage.

The output analog voltage can be converted to digital form using ADC so that a microcontroller can process it.

For more information about LM35 and how to use it, refer to the topic LM35 Temperature Sensor in the sensors and modules section.

NodeMCU ADC can be used to measure analog voltage from LM35 and so temperature which is in proportion to the analog voltage. To know about ADC of NodeMCU refer to NodeMCU ADC with ESPlorer IDE and NodeMCU ADC with Arduino IDE.

 

Connection Diagram of LM35 With NodeMCU

NodeMCU LM35 Interfacing Diagram
NodeMCU Interfacing with LM35 

 

 

Measure Temperature using LM35 and NodeMCU

Here, the LM35 output is given to analog pin A0 of NodeMCU. This analog voltage is converted to its digital form and processed to get the temperature reading.

We can write codes for NodeMCU DevKit in either Lua Script or C/C++ language. We are using ESPlorer IDE for writing code in Lua scripts and Arduino IDE for writing code in C/C++. To know more refer to Getting started with NodeMCU using ESPlorer IDE (which uses Lua scripting for NodeMCU) and Getting started with NodeMCU using Arduino IDE (which uses C language-based Arduino sketches for NodeMCU).

Lua Script for LM35

Vref = 3.3
resolution = Vref/1023

analogVtg = adc.read(0)
if analogVtg> 1023 then
analogVtg = 1023
end
temperature = (analogVtg * resolution)*100
print('LM35 Temperature:', temperature)

 

ESPlorer Serial Output Window

ESPlorer Serial monitor output window for LM35 temperature measure

ESPlorer output window for LM35 temperature

 

LM35 Code for NodeMCU using Arduino IDE

float vref = 3.3;
float resolution = vref/1023;

void setup() {
 Serial.begin(9600);  /* Define baud rate for serial communication */
}

void loop() {
 float temperature = analogRead(A0);
 temperature = (temperature*resolution);
 temperature = temperature*100;
 Serial.println(temperature);
 delay(1000);
}

 

Arduino Serial Output Window

Arduino Serial monitor output window for LM35 temperature measure

Arduino serial monitor window for LM35

Components Used

LM35 Temperature Sensor
LM35 is a sensor which is used to measure temperature. It provides electrical output proportional to the temperature (in Celsius).
1
NodeMCU
NodeMCUNodeMCU
1
ESP12F
ESP12E
1

Downloads

LM35 Datasheet Download
NodeMCU LM35 source codes Download
Ad