Introduction: Interface LM35 With NodeMCU
Hello Makers,
I'm back with another simple Instructable.
In this Instructable we will learn how to interface LM35 with NodeMCU.
Step 1: Materials Required
Here is the list of components required to get started with the Instructable,
Hardware Components
- NodeMCU
- LM35 Temperature Sensor
- Bread Board
- 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.
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 sensor
int 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); }
Attachments
Step 5: Upload the Code
- Goto Tools
- Board > NodeMCU 1.0 (ESP - 12E Module)
- 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
1 Person Made This Project!
- RottenRonnie48 made it!
11 Comments
6 months ago
hello the lm35 requires a 4v or higher from what I'm seeing but the esp8266 is a 3.3v logic level. how are you getting it to work without burning up the esp8266?
6 months ago on Step 6
Bonjour je suis LANE Romuald
Merci Beaucoup pour cette ressource elle a résolut un de mes problèmes de compréhension.
1 year ago
hello I am Shreya
I thank you so very much for this information because it helped me a lot.
3 years ago
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.
4 years ago
I think you might have made a calculation error. The analogue input measures up to 1 volt not 3.3 volt
Reply 4 years ago
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
Question 4 years ago
Thank you! It works but temperature is totally wrong: room temperature about 80 C instead of 22 C.. Any help please?
4 years ago
Hello,
The LM35 minimum power supply is 4V. It cannot work without an external power supply on a NodeMCU. Check paragraph 6.3 of http://www.ti.com/lit/ds/symlink/lm35.pdf
Reply 4 years ago
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.
4 years ago
I am doing the same connection on PCB but it is not showing proper result? Plz tell me any solution??
Reply 4 years ago
The nodemcu already gives a full 1024 reading at 1 volt so the calculation is wrong. Also it needs a minimum voltage of 4 volt I believe