LM35 Interfacing with NodeMCU

LM35 Interfacing with NodeMCU


Introduction

LM35 temperature sensor
LM35 temperature sensor
LM35 is a temperature sensor which can measure temperature in the range of -55°C to 150°C.
It is a 3-terminal device that provides analog voltage proportional to the temperature. Higher the temperature, 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 the topic LM35 Temperature Sensorin 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 NodeMCU ADC with ESPlorer IDE and NodeMCU ADC with Arduino IDE.

Interfacing Diagram

NodeMCU LM35 Interfacing Diagram
NodeMCU LM35 Interfacing Diagram

Example

Here, 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 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

Arduino Sketch for LM35

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


Supporting Files
Source Code
Attached File

No comments:

Post a Comment