Skip to content

Project 1.2.6

Rain Detection Buzzer Alert

Overview

Build a rain alert system with a buzzer and LED.

This project demonstrates digital weather detection.

The final result is a buzzer and LED that activate when water is detected on the rain sensor.

Required Components

Pico 2 W
Raspberry Pi Pico 2 W
Rain Sensor
Rain sensor module
Buzzer
Active buzzer
LED
LED
Resistor
220Ω resistor
Breadboard
Breadboard
Jumper Wires
Jumper wires

Circuit Connections

Component Pin Connects To Pico GPIO / Physical Pin Number Notes
Rain sensor VCC 3.3V Physical pin 36 Safer for Pico logic
Rain sensor GND GND Physical pin 38
Rain sensor DO GPIO 1 GPIO 1 / physical pin 2 Digital 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

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.

Circuit 2

Step 2: Place the Rain Sensor Module

Place the rain sensor module on the breadboard, or place the sensing plate beside the breadboard where it can safely detect water.

Identify the module pins before wiring: VCC, GND, and DO.

Check the printed pin labels on the module because pin order can vary.

Circuit 3

Step 3: Connect the Rain Sensor VCC

Connect the rain sensor VCC pin to 3.3V.

Circuit 4

Step 4: Connect the Rain Sensor GND

Connect the rain sensor GND pin to GND.

Circuit 5

Step 5: Connect the Rain Sensor DO Pin

Connect the rain sensor DO pin to GPIO 1.

This digital pin tells the Pico when rain or water is detected.

Circuit 6

Step 6: Place the Active Buzzer

Place the active buzzer on the breadboard.

Identify the positive (+) and negative (-) pins before wiring.

Circuit 7

Step 7: Connect the Buzzer Positive Pin

Connect the buzzer positive (+) pin to GPIO 0.

Circuit 8

Step 8: Connect the Buzzer Negative Pin

Connect the buzzer negative (-) pin to GND.

Circuit 9

Step 9: Place the Alert LED

Place the LED on the breadboard with its legs in different rows.

The long leg is the anode (+). The short leg is the cathode (-).

Circuit 10

Step 10: Connect the LED Through a Resistor

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.

Circuit 11

Wiring Check

Pico 2W is placed correctly across the breadboard center gap

Rain sensor VCC connects to 3.3V

Rain sensor GND connects to GND

Rain sensor DO connects to GPIO 1

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

No loose jumper wires

Safety Note

Water should touch only the rain sensor plate. Keep the Pico, breadboard, USB cable, and jumper wires dry.

Testing Individual Components

Before running the full project, test each part separately. This makes it easier to find wiring or code problems.

Rain sensor test

Check the digital output first.

from machine import Pin
import time
rain = Pin(1, Pin.IN)
while True:
    print(rain.value())
    time.sleep(0.2)

Expected test result: The printed value changes when the sensor plate gets wet and then dries.

Buzzer and LED test

Check the alert outputs before combining them.

from machine import Pin
import time
buzzer = Pin(0, Pin.OUT)
led = Pin(2, Pin.OUT)
buzzer.on()
led.on()
time.sleep(1)
buzzer.off()
led.off()

Expected test result: The buzzer sounds and the LED lights for 1 second.

Full Project Code

After completing and checking the circuit connections, open Thonny IDE. Copy and paste the code below into a new file, or upload the project file to the Raspberry Pi Pico 2 W, then run it from Thonny.

from machine import Pin
import time

rain_sensor = Pin(1, Pin.IN)
buzzer = Pin(0, Pin.OUT)
led = Pin(2, Pin.OUT)

print('Rain alert ready')

while True:
    if rain_sensor.value() == 1:
        buzzer.on()
        led.on()
        print('RAIN DETECTED')
    else:
        buzzer.off()
        led.off()
        print('No rain')
    time.sleep(0.2)

How the Code Works

Code Section What It Does Why It Matters
Rain sensor input Reads the digital output from the rain module This tells the Pico whether water is detected
Buzzer control Turns the buzzer on during rain detection Creates an audible alert
LED control Lights an LED during rain detection Creates a visual alert
Loop delay Waits briefly before the next check Keeps the Shell readable

Expected Result

When water is detected on the rain sensor, the buzzer sounds and the LED turns on. When the sensor dries, both turn off.

Troubleshooting

Problem Possible Cause Solution
Sensor never changes Wrong pin or no power Check VCC, GND, and DO wiring
Alert always active Sensor still wet or threshold module setting too sensitive Dry the plate and adjust the module trim pot if available
Buzzer works but LED does not LED polarity or resistor issue Recheck LED orientation and resistor placement