Skip to content

Project 1.8.4: Online Temperature Monitor

Beginner Embedded Systems Project Using Raspberry Pi Pico 2 W and MicroPython

Pico 2 W Diagram

Pico 2 W Pinout


Overview

Build a temperature monitor that serves live BME280 data on a web page over Wi-Fi.

This project demonstrates combining Wi-Fi networking with an I2C sensor.

The final result should open a browser page that shows the current temperature and refreshes automatically.

Required Components

Raspberry Pi Pico 2 W
Raspberry Pi Pico 2 W
BME280 module
BME280 module
Breadboard
Breadboard
Jumper wires
Jumper wires

Circuit Connections

Component Pin Connects To Pico GPIO / Physical Pin Number Notes
BME280 VCC 3.3V Physical pin 36
BME280 GND GND Physical pin 38
BME280 SDA GPIO 8 GPIO 8 / physical pin 11 I2C0 SDA
BME280 SCL GPIO 9 GPIO 9 / physical pin 12 I2C0 SCL

Step-by-Step Assembly

Step 1: Place the Raspberry Pi Pico 2 W

Place the Pico 2 W on the breadboard so it sits across the center gap.

Step 1

Step 2: Place the BME280 Module

Place the BME280 module on the breadboard and identify VCC, GND, SDA, and SCL.

Step 2

Step 3: Connect BME280 Power

Connect BME280 VCC to 3.3V and BME280 GND to GND.

Step 3

Step 4: Connect BME280 I2C Pins

Connect BME280 SDA to GPIO 8 and BME280 SCL to GPIO 9.

Step 4


Testing Individual Components

I2C Scanner Test

from machine import Pin, I2C

i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
print([hex(addr) for addr in i2c.scan()])

BME280 Temperature Test

from machine import Pin, I2C
import BME280

i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
try:
    bme = BME280.BME280(i2c=i2c, address=0x76)
except OSError:
    bme = BME280.BME280(i2c=i2c, address=0x77)

print('Temperature:', bme.temperature)

Wi-Fi Connection Test

import network
import time

SSID = 'YOUR_WIFI_NAME'
PASSWORD = 'YOUR_WIFI_PASSWORD'

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)

for _ in range(15):
    if wlan.isconnected():
        break
    print('Connecting...')
    time.sleep(1)

print('Connected:', wlan.isconnected())
if wlan.isconnected():
    print('IP address:', wlan.ifconfig()[0])

Full Project Code

import network
import socket
import time
from machine import Pin, I2C
import BME280

SSID = 'YOUR_WIFI_NAME'
PASSWORD = 'YOUR_WIFI_PASSWORD'

i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
try:
    bme = BME280.BME280(i2c=i2c, address=0x76)
except OSError:
    bme = BME280.BME280(i2c=i2c, address=0x77)

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)

print('Connecting to Wi-Fi...')
for _ in range(15):
    if wlan.isconnected():
        break
    time.sleep(1)

if not wlan.isconnected():
    raise RuntimeError('Wi-Fi connection failed')

ip_address = wlan.ifconfig()[0]
print('Connected. Open http://{} in your browser'.format(ip_address))

def web_page():
    temperature_text = str(bme.temperature)
    html = """<!DOCTYPE html>
<html>
<head>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <meta http-equiv='refresh' content='5'>
    <title>Online Temperature Monitor</title>
</head>
<body style='font-family:Arial;text-align:center;padding:40px'>
    <h1>Online Temperature Monitor</h1>
    <h2>TEMP_TEXT</h2>
    <p>Page refreshes every 5 seconds</p>
</body>
</html>"""
    return html.replace('TEMP_TEXT', temperature_text)

address = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
server = socket.socket()
server.bind(address)
server.listen(1)

while True:
    client, client_address = server.accept()
    print('Client connected from', client_address)
    response = web_page()
    client.recv(1024)
    client.send('HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n'.encode())
    client.sendall(response.encode())
    client.close()

How the Code Works

Code Section What It Does Why It Matters
BME280 setup Creates the sensor object and tries common addresses Different boards may use 0x76 or 0x77
Wi-Fi setup Connects the Pico to the local network The browser page needs a network connection
web_page() Builds an HTML page with current temperature Turns sensor data into a browser view
Auto-refresh Refreshes every 5 seconds Shows changing values without manual reload

Expected Result

After entering your Wi-Fi details, the Shell prints an IP address. Opening that address in a browser shows the current BME280 temperature and refreshes every 5 seconds.


Troubleshooting

Problem Possible Cause Solution
No temperature reading BME280 not detected or wrong address Run the I2C scanner and try 0x76 or 0x77
Wi-Fi does not connect Wrong network details Recheck SSID/password and use 2.4 GHz Wi-Fi
Browser shows no useful data Library or wiring issue Run the BME280 temperature test first