Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Building a Raspberry Pi Pico W & LM35 Web Server
Raspberry Pi Raspberry Pi Pico W Projects

Building a Raspberry Pi Pico W & LM35 Web Server

Mamtaz AlamBy Mamtaz AlamUpdated:February 2, 20254 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Building a Raspberry Pi Pico W & LM35 Web Server
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this project, we’ll use MicroPython on the Raspberry Pi Pico W to read the temperature data from the LM35 sensor and serve it on a web page through the Pico W’s built-in Wi-Fi. This will enable easy and efficient temperature monitoring. Moving away from traditional methods such as utilizing an Raspberry Pi Pico & LM35 for Terminal display, we’ll use the Raspberry Pi Pico W’s ability to host a web server.

The web server will display the temperature readings on a webpage, accessible through any standard web browser. This technique modernizes the method of displaying temperature readings and facilitates remote monitoring of temperature over a local network.

The LM35 Temperature Sensor is an analog device, with its output directly proportional to the Centigrade temperature. It provides a temperature measurement range from -55°C to +150°C with an accuracy of +/- 0.75°C. This broad measurement range and notable accuracy make the LM35 a versatile choice for diverse temperature sensing applications.


Bill of Materials

Following are the required components for this tutorial.

S.N.ComponentsQuantityPurchase Link
1Raspberry Pi Pico W 1Amazon | AliExpress | SunFounder
2LM35 Temperature Sensor1Amazon | AliExpress| SunFounder
3Jumper Wires10Amazon | AliExpress | SunFounder
4Breadboard1Amazon | AliExpress | SunFounder




LM35 Temperature Sensor

LM35 Temperature Sensor

The LM35 series are precise temperature sensors with an output voltage linear to the Centigrade temperature, eliminating the need to subtract a constant voltage for Centigrade scaling unlike Kelvin-calibrated sensors. It achieves typical accuracies of ±0.25°C at room temperature and ±0.75°C across a -55°C to 150°C range without external calibration.

LM35 Pinout

Its cost-effectiveness is ensured by wafer-level trimming and calibration. The LM35’s low-output impedance, linear output, and inherent calibration facilitate easy interfacing with circuitry. It operates on single or dual power supplies, drawing only 60 µA, which minimizes self-heating to under 0.1°C in still air.

Features

  1. Calibrated directly in Degree Celsius (Centigrade)
  2. Linear at 10.0 mV/°C scale factor
  3. 0.5°C accuracy guarantee-able (at a25°C)
  4. Rated for full -55°C to a 150°C range.s
  5. Suitable for remote applications
  6. Low cost due to wafer-level trimming
  7. Operates from 4 to 30 volts
  8. Less than 60 mA current drain
  9. Low self-heating, 0.08°C instill an air
  10. Non-linearity only 0.25°C typical
  11. Low impedance output, 0.1Ωfor 1 mA load




Connecting LM35 Temperature Sensor with Raspberry Pi Pico W

Let’s connect the LM35 Temperature Sensor with the Raspberry Pi Pico W Board. The process for connecting the sensor is very simple.

LM35 Temperature Sensor with Raspberry Pi Pico W

  • Connect the VCC of the LM35 to the 3.3V (Vin) on the Pico W.
  • Connect the GND of the LM35 to a GND pin on the Pico W.
  • Finally, connect the Vout (output) of the LM35 to a GP26 on the Pico W

LM35 Raspberry Pi Pico W

For making the connections, a breadboard & jumper wires can be used.


Building a Raspberry Pi Pico W & LM35 Web Server

Lets write a MicroPython Code to build a Raspberry Pi Pico W & LM35 based Web Server, where we can display the temperature reading dynamically without refreshing the webpage.

The following two code sets up a Raspberry Pi Pico W as a web server to display temperature readings from an LM35 temperature sensor. It first establishes a Wi-Fi connection using predefined SSID and password, then listens for incoming HTTP requests on port 80. Upon receiving a request, it checks if the request is to read the temperature; if so, it computes the temperature in Celsius and Fahrenheit using the sensor’s reading, and responds with these values in JSON format.

The web server displays temperature readings in Celsius and Fahrenheit, which are dynamically updated through JavaScript fetching data from the server.


main.py

Copy the following code and paste it on the editor window of Thonny IDE. Save it to the Raspberry Pi Pico W board with the name main.py

1
2
ssid = '*********'
password = '*********'

Change the WiFi SSID & Password from the above lines.

Here is the full code for the project.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import network
import socket
import machine
import utime
from html import html_page  # Import the HTML content from html.py
 
# Initialize ADC for LM35 temperature sensor
# Note: Adjust the ADC pin according to your setup
LM35 = machine.ADC(26)
Cal_Offset = -1650  # Calibration offset
 
# Function to compute temperature from LM35 sensor readings
def compute_temp(avg_a):
    lm35_a = avg_a + Cal_Offset
    lm35_v = lm35_a * .00005  # Convert ADC value to voltage
    temp_c = round((lm35_v * 100), 1)  # Convert voltage to Celsius
    temp_f = round((temp_c * 1.8 + 32), 1)  # Convert Celsius to Fahrenheit
    return temp_c, temp_f
 
# Connect to Wi-Fi
ssid = 'Kaushar'
password = 'Z@kiza1nyfc'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
 
# Wait for connection
while not wlan.isconnected():
    utime.sleep(1)
 
print('Connected to Wi-Fi')
ip_address = wlan.ifconfig()[0]  # Get the IP address
print('IP Address:', ip_address)
 
# Create a socket to listen on port 80
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
 
print('Listening on port 80...')
 
# Main loop
while True:
    conn, addr = s.accept()
    print('Got a connection from %s' % str(addr))
    request = conn.recv(1024)
    request_str = str(request)
    print('Content = %s' % request_str)
    
    # Check if the request is for reading the temperature
    if 'readTemp' in request_str:
        temp_c, temp_f = compute_temp(LM35.read_u16())  # Get temperature readings
        response = '{{"celsius": "{}", "fahrenheit": "{}"}}'.format(temp_c, temp_f)
        conn.send('HTTP/1.1 200 OK\n')
        conn.send('Content-Type: application/json\n')
        conn.send('Connection: close\n\n')
        conn.sendall(response)
    else:
        # Serve the HTML page for any other request
        conn.send('HTTP/1.1 200 OK\n')
        conn.send('Content-Type: text/html\n')
        conn.send('Connection: close\n\n')
        conn.sendall(html_page)
 
    conn.close()

html.py

Copy the following code and paste it to the editor window of Thonny IDE. Save it to the Raspberry Pi Pico W board with the name html.py.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# html.py
 
html_page = """<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Temperature Monitor</title>
  <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100;400;700&display=swap" rel="stylesheet">
  <style>
    body {
      margin: 0;
      padding: 20px;
      font-family: 'Roboto', sans-serif;
      background-color: #f0f0f0;
      color: #333;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 90vh;
      background-image: linear-gradient(120deg, #a1c4fd 0%, #c2e9fb 100%);
    }
    .container {
      text-align: center;
      padding: 2em;
      background: white;
      border-radius: 20px;
      box-shadow: 0 10px 25px rgba(0,0,0,0.2);
      max-width: 400px;
      transition: transform 0.5s ease;
    }
    h1 {
      color: #017bff;
      font-weight: 400;
    }
    .temperature {
      margin: 20px 0;
      padding: 15px 0;
      background: rgba(255, 255, 255, 0.9);
      border: 1px solid #ddd;
      border-radius: 20px;
      box-shadow: 0 5px 15px rgba(0,0,0,0.1);
      transition: all 0.5s ease;
    }
    .temperature:hover {
      background: #017bff;
      color: #fff;
      cursor: pointer;
    }
    .temperature span {
      display: block;
      font-size: 2.5em;
      font-weight: 700;
    }
    .degree-symbol {
      font-size: 0.5em;
      vertical-align: super;
    }
    @keyframes fadeIn {
      from { opacity: 0; transform: scale(0.95); }
      to { opacity: 1; transform: scale(1); }
    }
    @media (max-width: 600px) {
      .container {
        padding: 1em;
      }
      .temperature span {
        font-size: 2em;
      }
    }
  </style>
</head>
<body>
  <div class="container" style="animation: fadeIn 1s ease-out;">
    <h1>Temperature Monitor</h1>
    <div class="temperature" onclick="fetchTemperature()">
      <span id="TempValueCelsius">--</span>
      <span class="degree-symbol">&deg;C</span>
    </div>
    <div class="temperature" onclick="fetchTemperature()">
      <span id="TempValueFahrenheit">--</span>
      <span class="degree-symbol">&deg;F</span>
    </div>
  </div>
 
  <script>
    function fetchTemperature() {
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          var data = JSON.parse(this.responseText);
          document.getElementById("TempValueCelsius").innerHTML = data.celsius;
          document.getElementById("TempValueFahrenheit").innerHTML = data.fahrenheit;
          animateTemperature();
        }
      };
      xhttp.open("GET", "readTemp", true);
      xhttp.send();
    }
    
    function animateTemperature() {
      var temps = document.querySelectorAll('.temperature');
      temps.forEach(function(temp) {
        temp.style.transform = 'scale(1.05)';
        setTimeout(function() {
          temp.style.transform = 'scale(1)';
        }, 500);
      });
    }
    
    // Initial fetch
    fetchTemperature();
    // Set interval to fetch temperature every 5 seconds
    setInterval(fetchTemperature, 2000);
  </script>
</body>
</html>
"""




Checking the Temperature Readings on Webpage

To begin with reading the temperature, run the main.py code on your Raspberry Pi Pico W. The Terminal window will display the IP Address of the Raspberry Pi Pico W.

Open a web browser and enter this IP address to access the webpage, where you will see the live temperature readings update automatically.

Building a Raspberry Pi Pico W & LM35 Web Server Webpage

The webpage will show real-time temperature data in both Celsius and Fahrenheit, dynamically updated at intervals set by the JavaScript in the HTML code.

Ensure your computer or smartphone is connected to the same local network as the Raspberry Pi Pico W for accessibility. If you encounter any issues, check the Raspberry Pi Pico W’s Wi-Fi connection and ensure the server is running without errors.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleInterfacing AD8495 K-Type Thermocouple Amplifier with Arduino
Next Article AD8495 K-Type Thermocouple Amplifier Raspberry Pi Pico

Related Posts

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

Updated:July 24, 2025
Interface BMI160 with Raspberry Pi Pico & MicroPython

Interface BMI160 with Raspberry Pi Pico & MicroPython

Updated:February 2, 20253K
Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Updated:February 2, 202513K
Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Updated:February 2, 20253K
Modbus RTU with Raspberry Pi Pico & Micropython

Modbus RTU with Raspberry Pi Pico & MicroPython

Updated:February 2, 20258K
Fever Detector with MLX90640 & OpenCV Raspberry Pi

Thermal Fever Detector with MLX90640 & OpenCV Raspberry Pi

Updated:February 2, 20256K
Add A Comment

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 16, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • IoT Based PM & Air Quality Monitoring System using ESP32
    IoT Based PM & Air Quality Monitoring System using ESP32
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • Designing of MPPT Solar Charge Controller using Arduino
    Designing of MPPT Solar Charge Controller using Arduino
  • RS-485 Simplex Communication with Arduino & MAX485
    RS-485 Simplex Communication with Arduino & MAX485
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.