This is a simple DIY project on internet of things applications. How to monitor room temperature via WiFi? You can see the temperature on your mobile phone, laptop or desktop computer through this DIY project. The popular LM35 temperature sensor is interfaced with the Nodemcu ESP8266-12e WiFi module. Nodemcu takes raw temperature voltage in lm35 format, converts the voltage to real temperature using its analog to digital converters. The final temperature is calculated in Celsius form. Once the Celsius temperature is calculated, it is converted to Fahrenheit and both values are forwarded to clients connected to nodemcu. You can see the temperature on mobile and desktop devices.
Nodemcu is working as a server. Serving a web page. Mobile or desktop device is our client. Looking for server temperature. Note: Both the server and client must be connected to the same WiFi network to work properly. I write a good tutorial about the LM35 pinout and the working principle. If you are new and don't know about the pinout and operation of the LM35 temperature sensor, I advise you to first follow a simple tutorial. Operation and pinout configuration of the LM35.
If you followed the tutorial above, you can easily understand the calculated values below. Most of the DIY projects I've been through don't explain how to convert the LM35's output voltage into an actual temperature reading. Even most LM35 online tutorials do not calculate accurate temperature reading and their temperature measurement technique is totally wrong. So I decided to explain in depth what is going on.
Nodemcu is working as a server. Serving a web page. Mobile or desktop device is our client. Looking for server temperature. Note: Both the server and client must be connected to the same WiFi network to work properly. I write a good tutorial about the LM35 pinout and the working principle. If you are new and don't know about the pinout and operation of the LM35 temperature sensor, I advise you to first follow a simple tutorial. Operation and pinout configuration of the LM35.
If you followed the tutorial above, you can easily understand the calculated values below. Most of the DIY projects I've been through don't explain how to convert the LM35's output voltage into an actual temperature reading. Even most LM35 online tutorials do not calculate accurate temperature reading and their temperature measurement technique is totally wrong. So I decided to explain in depth what is going on.
Driving formula for Nodemcu and LM35 temperature conversion rate
- The Nodemcu's analog pins can measure up to 3.3 volts OR the voltage it is working at 3.3 volts.
- The Nodemcu analog pin resolution is 1023 starting at 0. At 3.3 volt input it counts up to 1023.
- The maximum voltage output Lm35 is 1500mV (at 150 degrees centigrade). 1500mV is equal to 1500/1000 = 1.5 volts. So Lm35 with maximum output of 1.5 volts.
- The Nodemcu analog pin count for 1.5 volts is equal to (1.5 / 3.3)*1023 = 465 . At 3.3 volts it is 1023 and at 1.5 volts it is 465.
- New resolution Nodemcu-Lm35 = 465/150 = 3.1 . Now, if the nodemcu analog pin counts 3.1, it equals a 1 degree change in the LM35's Centigrade/Celsius temperature.
As the Lm35 operates on 5 volts, it is powered by an external 5 volt signal. The Nodemcu works at 3.3 volts, so it is not possible to power the lm35 with nodemcu output voltage. The Lm35 output is connected to analog channel 0 of the nodemcu. Note that the ground of the LM35 and Nodemcu must be connected to each other for proper measurement of the analog signal.
Coming to the code part. The code is written and compiled in Arduino IDE. The ESP8266WiFi.h library is used in the project. Make sure you have installed this library in your Arduino library package. Now enter the SSID and password of the WiFi router you want your nodemcu to be connected to. Your client (mobile, desktop or laptop) must be connected to the same WiFi router to which you will connect your server (nodemcu).
Select the correct board in your Arduino IDE and load the code into Nodemcu. After uploading the code to nodemcu, open the Arduino serial monitor. You will see that the nodemcu will receive an IP from your WiFi router and the nodemcu server will start up. After the server boots successfully, a URL will be displayed on the serial monitor.
This URL is actually the address of the web page served by the server (nodemcu). Enter this URL into your mobile or desktop browser and you will see a web page like. A button with the text Update temperature is present on the page. Each time you press the Celsius and Fahrenheit button the temperature values will be updated.
What happens when you press the “Update Temperature” button? The Loop function is always looking for the client's request. When the refresh button is pressed, the HTTP request reaches the server (nodemcu). In the loop function, it is compared with the request format embedded in the code. If the client request matches the request format in the server code. The server starts reading the remaining parameters of the request and performs the functions requested in the client's request. In our case, it updates the readings from the lm35 temperature sensors and provides instant temperature readings. Nodemcu captures the updated readings and before closing the client's request it responds with the updated temperature values.
Download the project code. The code is written in Arduino IDE. The folder contains the project's .ino file. You may need to include the ESP8266WiFi.h header library in the Arduino libraries folder. Please give us your feedback on the project.
Nodemcu Wifi Temperature Sensor .ino