Chapter 3
Chapter 3
The LM35 is a widely used analog temperature sensor known for its accuracy and linear output. It
can measure temperatures ranging from -55°C to +150°C with a typical accuracy of ±0.5°C. The
sensor has a linear transfer function of 10 mV/°C, meaning the output voltage changes by 10
millivolts for every degree Celsius change in temperature. It requires minimal external components,
operates on a single supply voltage, and consumes low power. The LM35 is commonly employed in
applications such as environmental monitoring, HVAC systems, industrial temperature control,
weather stations, medical devices, and IoT-based temperature sensing systems. Overall, it is a
reliable and easy-to-use temperature sensor with various practical applications.
3.1.2. NodeMCU Microcontroller
The NodeMCU is an open-source development board based on the ESP8266 Wi-Fi module. It
combines a microcontroller with Wi-Fi capabilities, making it suitable for IoT projects. It has GPIO
pins for interfacing with electronic components, can be programmed using IDEs like Arduino. The
board offers USB connectivity and is known for its affordability, ease of use, and strong community
support. The pin out diagram of nodeMcu is shown in figure 3
I. Voltage Requirement: The components used in the thermometer system, including the
microcontroller and sensors, typically operate at a voltage level of 5V. Therefore, it is crucial to
provide a power supply that can deliver a steady 5V DC output.
III. Power Supply Options: There are various options for obtaining a 5V power supply for the IoT
digital thermometer, depending on the specific requirements and constraints of the project
III. Battery Power: require a portable or battery-powered thermometer, you can use a battery pack
or rechargeable battery
In our case we used a ready made power supply that can deliveree upto 1A of current at 5v.
Figure 4. A 5v Dc Power
supply
The circuit for an IoT digital thermometer using NodeMCU, LM35 sensor, and a 5V power supply
is shown in figure 5. Here is a step-by-step guide on how we construct the circuit.
3.2.1 Components Required
I. NodeMCU (ESP8266 development board)
II. LM35 temperature sensor
III. Verooard
4. Jumper wires
5. 5V power supply (USB charger or power bank)
6. Soldering Iron
I. We connect the NodeMCU to the breadboard. Ensuring that the NodeMCU is properly positioned
across the middle gap of the veroboard, with half the pins on each side.
II. Then connect the 5V power supply to the NodeMCU. Use a USB cable to connect the 5V power
supply (e.g., USB charger) to the NodeMCU. Connect the USB cable's positive (red) wire to the
"Vin" pin of the NodeMCU and the negative (black) wire to the "GND" pin of the NodeMCU.
III. Also, we connect the LM35 sensor to the NodeMCU. The LM35 sensor has three pins: VCC,
GND, and OUT.
- Connected the LM35's VCC pin to the 3.3V pin of the NodeMCU.
- Connected the LM35's GND pin to the GND pin of the NodeMCU.
- Connected the LM35's OUT pin to any of the analog input pins (e.g., A0) of the NodeMCU.
IV. Connect a 10kΩ resistor between the LM35's OUT pin and the 3.3V pin of the NodeMCU. This
resistor is used as a pull-up resistor to stabilize the voltage output from the LM35.
IV. Finally, connect the NodeMCU to your computer using a USB cable to power it up.
We successfully constructed the circuit for the IoT digital thermometer using NodeMCU and the
LM35 temperature sensor. The NodeMCU can now read the temperature data from the LM35
sensor and transmit it to an IoT platform or any internet browser in order perform any other desired
actions based on the temperature readings.
Start server
Print local IP address
Loop:
Read analog value from A0 pin
Convert analog value to temperature in Celsius
Convert temperature to Fahrenheit
End
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);
Serial.print(".");
Serial.println("");
Serial.println("WiFi is connected");
server.begin();
Serial.println("Server started");
Serial.println(WiFi.localIP());
void loop() {
Serial.print(temp_celsius);
Serial.print(temp_fahrenheit);
Serial.println(" Fahrenheit");
WiFiClient client = server.available();
client.println("Content-Type: text/html");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println(temp_celsius);
client.println(temp_fahrenheit);
client.print("</p>");
client.println("</html>");
delay(1000);
The code continuously reads the LM35 sensor's output, calculates the temperature in both Celsius
and Fahrenheit, and provides the temperature values via a web server running on the ESP8266. This
allows you to access the temperature data by accessing the IP address of the ESP8266 module in a
web browser.