Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsA relay HAT plugs straight onto the Pi's 40-pin header, so there is no loose wiring between the Pi and the relays. This timer runs a 12 V pump or solenoid valve for a set time each morning and evening, with a manual test mode.
Relays here switch only low-voltage DC loads. Mains wiring must be done by a qualified electrician in a closed, earthed box.
Tick anything you already have and the total updates.
T-Cobbler breakout with cable to test GPIO wiring on a breadboard
Three relays on GPIO 26, 20 and 21, active low
Brings the header to a breadboard for testing other parts
Follow the colours: red is power, dark grey is ground, blue is a signal.
The Pi uses its own USB-C supply; the valve or pump uses a separate 12 V supply through the relay contacts.
water.py# Waveshare 3-channel relay HAT: CH1 = GPIO26, CH2 = GPIO20, CH3 = GPIO21, relays switch on when the pin is LOW
import sys, time
from gpiozero import OutputDevice
relays = [OutputDevice(p, active_high=False, initial_value=False) for p in (26, 20, 21)]
def run(ch, seconds):
relays[ch].on()
try:
time.sleep(seconds)
finally:
relays[ch].off()
if len(sys.argv) > 1 and sys.argv[1] == "test":
for ch in range(3):
run(ch, 2)
else:
# usage: python3 water.py <channel 1-3> <minutes>
ch, minutes = int(sys.argv[1]) - 1, float(sys.argv[2])
run(ch, minutes * 60)
crontab.txt30 6 * * * /usr/bin/python3 /home/pi/water.py 1 10
30 18 * * * /usr/bin/python3 /home/pi/water.py 1 10
That is the pins floating before the script runs; it stops once gpiozero sets them. Use a normally-closed valve so it stays shut.
Check the HAT jumpers connect the relay inputs to the GPIO pins.
The supply is too weak; solenoid valves need their rated current.
The relays are rated for it, but mains work needs a qualified electrician and a closed, earthed enclosure.
The Pi keeps time while powered; add an RTC battery for long outages.
Yes, through an ADC such as an ADS1115 on I2C.
4 parts: T-Cobbler GPIO Breakout with Cable for Raspberry Pi, Raspberry Pi 5 with 4GB RAM, Waveshare 3-Channel Relay HAT for Raspberry Pi 3/4 and 40-Pin T-Type GPIO Extension Board for Raspberry Pi. On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 2 hours. The build on this page has 5 steps.
No. This page has the complete, tested code (water.py and crontab.txt).
About ₹15,591 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Driving active-low relays with gpiozero; Scheduling with cron; Keeping 12 V loads apart from the Pi.
Relays here switch only low-voltage DC loads. Mains wiring must be done by a qualified electrician in a closed, earthed box.
Ideas that reuse this build: Pi 5 NVMe home server. They are listed under Take it further on this page.
Your first MicroPython project: temperature and humidity on an OLED.
A web page with ON and OFF buttons that switches a relay over Wi-Fi.
A warm ring light that fades up at dusk and down at dawn.
Turn a Pi and a touchscreen into a home command centre with a clock and to-do list.
Learning project. Check every circuit and the datasheet of each part before you power it up.