Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsA first MicroPython program with real logic in it. The lights run green, amber, red, red and amber, like a real junction. Press the crossing button and the green phase is cut short so people can cross sooner. Students can see how a simple program becomes a state machine.
Tick anything you already have and the total updates.
Three indicator LEDs, each through a 330 Ω resistor to its pin.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico traffic light with a pedestrian button (MicroPython)
from machine import Pin
import time
red, yellow, green = Pin(13, Pin.OUT), Pin(14, Pin.OUT), Pin(15, Pin.OUT)
button = Pin(16, Pin.IN, Pin.PULL_UP)
waiting = False
def show(r, y, g):
red.value(r); yellow.value(y); green.value(g)
def wait(seconds):
# waits, but remembers if someone pressed the crossing button meanwhile
global waiting
end = time.ticks_add(time.ticks_ms(), int(seconds * 1000))
while time.ticks_diff(end, time.ticks_ms()) > 0:
if button.value() == 0:
waiting = True
time.sleep_ms(20)
while True:
show(0, 0, 1); wait(8 if not waiting else 3) # green for cars, shorter if someone is waiting
show(0, 1, 0); wait(2)
show(1, 0, 0)
print("Walk" if waiting else "Red")
waiting = False
wait(6) # red: people cross
show(1, 1, 0); wait(1.5) # red and amber together, then green
It is backwards: the long leg goes to the resistor.
The button is rotated 90°; legs on the same side are already connected. Turn it.
6 parts: Through-Hole LED Pack (Pack of 10), Tactile Push Button Switch, Resistor Assortment Kit (30 Values), Raspberry Pi Pico, Solderless Breadboard (830 points) 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 beginner project and takes about 45 minutes. The build on this page has 4 steps.
No. This page has the complete, tested code (main.py).
About ₹521 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.
Driving LEDs with resistors; Pull-ups and debouncing.
Ideas that reuse this build: Arduino traffic light model and 555 traffic light sequencer. 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.