# Interface LM35 With NodeMCU

19,850

25

8

Hello Makers,
I'm back with another simple Instructable.

In this Instructable we will learn how to interface LM35 with NodeMCU.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Materials Required

Here is the list of components required to get started with the Instructable,

Hardware Components

• NodeMCU
• LM35 Temperature Sensor
• Jumper Wires
• Micro USB Cable

Software Components

• Arduino IDE

## Step 2: Description

In general, an LM35 is a temperature sensor which is designed specifically to measure the hotness or coldness of an object.

LM35 is a precision IC temperature sensor with its output proportional to the temperature (in °C).

With LM35, the temperature can be measured more accurately than compared to the thermistor.

In my Instructable I'm using LM35 to measure the Room Temperature.

You can even interface, RGB Led's to make your project look more interesting.

## Step 3: Circuit Connections

The circuit connections are made as follows:

Pin 1 of the LM35 goes into +3v of the NodeMCU.

Pin 2 of the LM35 goes into Analog Pin A0 of the NodeMCU.

Pin 3 of the LM35 goes into Ground Pin (GND) of the NodeMCU.

Before you get started with coding you need Arduino IDE.
To download Arduino IDE and for NodeMCU setup, you can check my previous instructacle.

Interfacing Servo Motor With NodeMCU

## Step 4: Get Ready to Code

Before getting the Celsius reading of the temperature

The analog output voltage from LM35 must first be read from the Vout pin of LM35.

This will be the raw value divided by 1024 times 3300.

It is divided by 1024 because a span of 1024 occupies 3.3v.

Here we get the ratio of the raw value to the full span of 1024 and then multiply it by 3300 to get the millivolt value.

Since the output pin can give out a maximum of 3.3 volts (1024), 1024 represents the possible range it can give out.

Download the "LM35_NodeMCU.ino" file and open it up in the Arduino IDE.
Then Create a new sketch and paste the code below in the Arduino IDE and hit Upload.

You can tinker with it if you like based on the application, or just use it as it is.

CODE

```// initializes or defines the output pin of the LM35 temperature sensorint outputpin= A0;
//this sets the ground pin to LOW and the input voltage pin to high
void setup() {
Serial.begin(9600);
}void loop()       //main loop{
int analogValue = analogRead(outputpin);
float millivolts = (analogValue/1024.0) * 3300; //3300 is the voltage provided by NodeMCU
float celsius = millivolts/10;
Serial.print("in DegreeC=   ");
Serial.println(celsius);//---------- Here is the calculation for Fahrenheit ----------//float fahrenheit = ((celsius * 9)/5 + 32);
Serial.print(" in Farenheit=   ");
Serial.println(fahrenheit);
delay(1000);
}```

## Step 5: Upload the Code

1. Goto Tools
2. Board > NodeMCU 1.0 (ESP - 12E Module)
3. Port ( Choose the right Port )

**Make sure you have your NodeMCU model selected and the correct serial port ticked (see pics).

Then just click the Upload button**

## Step 6: Output

Now, you can monitor the Temperature.

That's all makers!
I hope you found this instructable most useful.

You can contact me by leaving a comment. If you like this instructable probably you might like my next ones.

Participated in the
Makerspace Contest 2017

## Recommendations

• ### Internet of Things Class

21,615 Enrolled

## 8 Discussions

If you directly connect LM35 output to ESP8266 A0 pin without a resistor divider, then the calculation formula should be: float millivolts = (analogValue/1024.0) * 1000; //
as the full range of ESP8266 ADC is 1000mV, which means the ADC internal reference is 1000mV. You may also check the LM35 output value with a digital multimeter as crosscheck.

I think you might have made a calculation error. The analogue input measures up to 1 volt not 3.3 volt

Lm35 have range of 0-150 celsius with constant voltage value of 10mV / C.
If have 5C the output of LM35 is 50mV
For 10C is 100mV
For 37 C is 370mV

Thank you! It works but temperature is totally wrong: room temperature about 80 C instead of 22 C.. Any help please?

You're right. I stumbled upon this as well.
However, the LM35 worked correctly, but I assume that it may be inreliable, less precise, etc.
I changed the circuit so that I'm using the Vin pin to power the LM35. This is @ 4.65V in my case.
Another solution could be building a simple charge pump using a cap-diode network and driving it with the ESPs PWM unit. But this also seems to be a little bit over engineered.
However, if we would not use a NodeMCU, but a pure ESP8266 instead this would be a solution if we want to use an LM35.

I am doing the same connection on PCB but it is not showing proper result? Plz tell me any solution??