Introduction: IoT Digital Thermometer Using LM35 and NodeMCU

About: hIOTron is an IoT Based company that offers IoT Platforms, IoT Solutions, IoT Training.

Here we will make a web server to display the temperature using LM35 as a temperature sensor.

Supplies

Hardware Components

NodeMCU - ESP12

LM35 Temperature Sensor For Arduino

Male-female connectors

Breadboard (generic)

Software Apps

Step 1: About Project

LM35 Temperature Sensor

LM35 sensor is an analog linear temperature sensor. Its output is equivalent to the temperature. LM35 is an analog sensor so we have to change this analog output to the digital output. For this here we use the ADC pin of NodeMCU which is described as A0. We will attach the output of LM35 to A0.

We have 3.3 V as output voltage on NodeMCU’s pins. So, we will utilize 3.3V as Vcc for LM35.

HTML Code to display Temperature on WebPage

We are now going to display temperature on a separate webpage so that we can easily access from anywhere with the help of the internet.

After uploading the code, open the serial monitor and hold the Reset button on NodeMCU. Now the board is connected to the Wi-Fi network which you have specified in your code and also you got the IP.

Copy and paste this IP in any web browser. Make assure that your system on which you are running the web browser should be connected to the same network. Then the temperature will be restored automatically in a web browser after every 10 Sec.

IoT Training Online will help you to get a thorough view of IoT Projects and applications.

Step 2: HTML Code to Display Temperature on WebPage

WiFiClient client = server.available(); client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // the connection will be closed after completion of the response client.println("Refresh: 10"); // update the page after 10 sec client.println(); client.println(""); client.println(""); client.print("

Digital Thermometer

"); client.print("

Temperature (*C)= "); client.println(temp_celsius); client.print("

Temperature (F) = "); client.println(temp_fahrenheit); client.print("

"); client.println(""); delay(5000); }

Step 3: Run a Code

#include const char* ssid = "*********"; // Your ssid const char* password = "***********"; // Your Password float temp_celsius = 0; float temp_fahrenheit = 0; WiFiServer server(80); void setup() { Serial.begin(115200); pinMode(A0, INPUT); Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi is connected"); server.begin(); Serial.println("Server started"); Serial.println(WiFi.localIP()); } void loop() { temp_celsius = (analogRead(A0) * 330.0) / 1023.0; // To convert analog values to Celsius We have 3.3 V on our board and we know that output voltage of LM35 varies by 10 mV to every degree Celsius rise/fall. So , (A0*3300/10)/1023 = celsius temp_fahrenheit = celsius * 1.8 + 32.0; Serial.print(" Temperature = "); Serial.print(temp_celsius); Serial.print(" Celsius, "); Serial.print(temp_fahrenheit); Serial.println(" Fahrenheit"); WiFiClient client = server.available(); client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // the connection will be closed after completion of the response client.println("Refresh: 10"); // update the page after 10 sec client.println(); client.println(""); client.println(""); client.print("

Digital Thermometer

"); client.print("

Temperature (*C)= "); client.println(temp_celsius); client.print("

Temperature (F) = "); client.println(temp_fahrenheit); client.print("

"); client.println(""); delay(5000); }