Project 1.2.18
Safety Alert Buzzer
Overview
Build a simple safety alert system using a flame sensor, buzzer, LED, OLED, and browser status page.
This project demonstrates latching an alert so it stays active until you reset it.
The final result should sound and display an alert when the flame sensor is triggered, and keep that warning latched until the alarm is reset after the hazard is gone.
Required Components
![]() Raspberry Pi Pico 2 W |
Flame sensor module | ![]() Active buzzer |
![]() LED |
![]() 220Ω resistor |
![]() SH1106 OLED display |
![]() Breadboard |
![]() Jumper wires |
| 2.4 GHz Wi-Fi network | Phone or computer browser |
Circuit Connections
| Component Pin | Connects To | Pico GPIO / Physical Pin Number | Notes |
|---|---|---|---|
| Flame sensor VCC | 3.3V | Physical pin 36 | |
| Flame sensor GND | GND | Physical pin 38 | |
| Flame sensor DOUT | GPIO 14 | GPIO 14 / physical pin 19 | Digital flame-detect output |
| Buzzer positive (+) | GPIO 0 | GPIO 0 / physical pin 1 | |
| Buzzer negative (-) | GND | Physical pin 38 | |
| LED anode (+) | 220Ω resistor then GPIO 2 | GPIO 2 / physical pin 4 | Alert LED |
| LED cathode (-) | GND | Physical pin 38 | |
| OLED VCC | 3.3V | Physical pin 36 | |
| OLED GND | GND | Physical pin 38 | |
| OLED SDA | GPIO 8 | GPIO 8 / physical pin 11 | I2C0 SDA |
| OLED SCL | GPIO 9 | GPIO 9 / physical pin 12 | I2C0 SCL |
Step-by-Step Assembly
Step 1: Place the Raspberry Pi Pico 2W
Place the Raspberry Pi Pico 2W on the breadboard so it sits across the center gap. Keep the USB port facing outward so you can easily connect it to your computer.

Step 2: Place the Flame sensor, Buzzer, LED, and OLED
Place the Flame sensor module on the breadboard or beside it where it can sense safely.
Place the active buzzer on the breadboard and identify its positive (+) and negative (-) pins.
Place the LED with its two legs in different breadboard rows.
Place the SH1106 OLED display module on the breadboard.
Identify VCC, GND, and DOUT on the sensor before wiring.

Step 3: Connect the Flame sensor
Connect Flame sensor VCC to 3.3V.
Connect Flame sensor GND to GND.
Connect Flame sensor DOUT to GPIO 14.

Step 4: Connect the Buzzer
Connect the buzzer positive (+) pin to GPIO 0.
Connect the buzzer negative (-) pin to GND.

Step 5: Connect the LED
Connect the LED long leg to one end of a 220Ω resistor.
Connect the other end of the resistor to GPIO 2.
Connect the LED short leg to GND.

Step 6: Connect OLED Power and I2C
Connect OLED VCC to 3.3V.
Connect OLED GND to GND.
Connect OLED SDA to GPIO 8.
Connect OLED SCL to GPIO 9.

Wiring Check
Pico 2W is placed correctly across the breadboard center gap
Flame sensor VCC connects to 3.3V
Flame sensor GND connects to GND
Flame sensor DOUT connects to GPIO 14
Buzzer positive pin connects to GPIO 0
Buzzer negative pin connects to GND
LED long leg connects through a 220Ω resistor to GPIO 2
LED short leg connects to GND
OLED VCC connects to 3.3V
OLED GND connects to GND
OLED SDA connects to GPIO 8
OLED SCL connects to GPIO 9
No loose jumper wires
Beginner Note
Flame sensor modules can react to infrared light as well as flame, so test carefully and read the module behavior.
Safety Note
Educational demo only. Use supervised testing, keep flames away from electronics, and never leave flames unattended.
Testing Individual Components
Before running the full project, test each part separately. This makes it easier to find wiring or code problems.
Flame sensor digital test
Check that the flame sensor output changes during a supervised flame test.
from machine import Pin
import time
sensor = Pin(14, Pin.IN)
while True:
print(sensor.value())
time.sleep(0.2)
Expected test result: During supervised testing, the printed value should change when the sensor detects the flame source.
Buzzer and LED test
Check the alarm outputs before using the full project code.
from machine import Pin
import time
buzzer = Pin(0, Pin.OUT)
led = Pin(2, Pin.OUT)
buzzer.on()
led.on()
time.sleep(0.5)
buzzer.off()
led.off()
Expected test result: The buzzer should sound and the LED should light briefly.
OLED text test
Check that the OLED driver works.
from machine import I2C, Pin
import sh1106
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
oled = sh1106.SH1106_I2C(128, 64, i2c)
oled.fill(0)
oled.text('Safety Alert', 12, 28, 1)
oled.show()
Expected test result: The OLED should show Safety Alert.
Wi-Fi connection test
Check that the Pico connects to Wi-Fi and prints its IP address.
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])
Expected test result: The Shell should show Connected: True and print an IP address.
Full Project Code
Upload and run this code after the individual tests work correctly.
import network
import socket
import time
from machine import I2C, Pin
import sh1106
SSID = 'YOUR_WIFI_NAME'
PASSWORD = 'YOUR_WIFI_PASSWORD'
flame = Pin(14, Pin.IN)
buzzer = Pin(0, Pin.OUT)
led = Pin(2, Pin.OUT)
alert_latched = False
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
oled = sh1106.SH1106_I2C(128, 64, i2c)
def web_page(detected, latched):
status = 'FIRE DETECTED!' if detected or latched else 'SAFE'
return '''<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<meta http-equiv='refresh' content='2'>
<title>Safety Alert</title>
</head>
<body style='font-family:Arial;text-align:center;padding:30px'>
<h1>Safety Alert Buzzer</h1>
<h2>{}</h2>
<p>Alert latch: {}</p>
<p><a href='/reset'><button>RESET ALARM</button></a></p>
<p>Educational demo only. Do not use for real safety protection.</p>
</body>
</html>'''.format(status, 'ON' if latched else 'OFF')
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))
address = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
server = socket.socket()
server.bind(address)
server.listen(1)
server.settimeout(0.2)
while True:
fire_detected = flame.value() == 1
if fire_detected:
alert_latched = True
buzzer.value(1 if alert_latched else 0)
led.value(1 if alert_latched else 0)
oled.fill(0)
oled.text('Safety Alert', 12, 8, 1)
oled.text('FIRE!' if alert_latched else 'SAFE', 34, 30, 1)
oled.text('RESET VIA WEB', 8, 52, 1)
oled.show()
try:
client, client_address = server.accept()
except OSError:
continue
request = client.recv(1024).decode()
if 'GET /reset' in request and not fire_detected:
alert_latched = False
print('Alarm reset')
response = web_page(fire_detected, alert_latched)
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 |
|---|---|---|
| Flame sensor input | Reads whether the sensor currently detects a flame source | This is the main safety trigger in the project |
| alert_latched | Keeps the alarm active after detection | This helps make sure the alert is not missed |
| RESET via web | Allows the alert to be cleared after the hazard is gone | The project needs a clear way to leave alarm mode |
| OLED and web status | Show the same current safety condition in two places | Students can monitor locally and remotely |
Expected Result
During supervised testing, if the flame sensor detects a flame source, the buzzer and LED should turn on and stay latched. The OLED and web page should show the alert. After the flame source is removed, using the RESET button on the web page should clear the latched alarm.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| False triggers happen often | Sensor is too sensitive or sees other infrared sources | Adjust the sensor if possible and keep bright heat sources away |
| No detection | Flame is too far away or sensor is not aimed correctly | Use a safe supervised test distance and point the sensor toward the flame source |
| RESET does not clear | Flame is still present so the latch re-triggers immediately | Remove the flame source fully before resetting |






