Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsAn ultrasonic sensor on the garage wall measures how far the car is. Green shows plenty of room, amber says slow down and red with beeps says stop. gpiozero's DistanceSensor class does all the timing, so the program is only a dozen lines.
Tick anything you already have and the total updates.
Sends a 40 kHz ultrasonic ping and times the echo to measure distance from 2 cm to about 4 m.
Active buzzer with a built-in oscillator: apply power and it beeps at about 2.3 kHz.
Red indicator LED for the alert state.; Yellow indicator LED.; Green indicator LED for the normal state.
Follow the colours: red is power, dark grey is ground, blue is a signal.
parking.py# Pi parking guide: an ultrasonic sensor, a buzzer and three LEDs
from gpiozero import DistanceSensor, Buzzer, LED
import time
sensor = DistanceSensor(echo=24, trigger=23, max_distance=2.0) # distance in metres
buzzer = Buzzer(27)
green, amber, red = LED(5), LED(6), LED(13)
while True:
d = sensor.distance * 100 # centimetres
green.value = d > 100
amber.value = 40 < d <= 100
red.value = d <= 40
if d <= 40:
buzzer.on() if d <= 15 else buzzer.beep(on_time=0.08, off_time=max(0.05, d / 100), n=1)
else:
buzzer.off()
print("%d cm" % d)
time.sleep(0.1)
TRIG and ECHO are swapped, or the sensor has no 5 V. Swap the two signal wires and check VCC.
Average several readings and keep wires short. Two HC-SR04s pinging at once will confuse each other.
Low-triggered module: invert the logic in setBuzzer().
LED is reversed; flip it. Check the 220 Ω resistor is in series.
8 parts: HC-SR04 Ultrasonic Range Finder Sensor Module, Active Buzzer Module 3.3–5V, 3 × Through-Hole LED Pack (Pack of 10), Resistor Assortment Kit (30 Values), Raspberry Pi Zero 2 W, Raspberry Pi Micro USB 5.1V 2.5A Power Supply, Official Raspberry Pi 32GB A2 Class Micro SD Card and Dupont Jumper Wires (40 pcs). Tools: Digital Multimeter and Wire Stripper and Cutter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 1–2 hours. The build on this page has 3 steps.
No. This page has the complete, tested code (parking.py). Install this library first: gpiozero (pre-installed).
About ₹4,010 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
Active vs passive buzzers; Current-limiting resistors for LEDs; Time-of-flight measurement with sound.
Ideas that reuse this build: Parking sensor and Reverse parking robot car. 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.