Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsA real theremin senses your hand without touching it. This one uses shadow instead: the less light reaches the LDR, the lower the note. The program learns the brightest and darkest levels as you play, so it works in any room.
Tick anything you already have and the total updates.
Light-dependent resistor with a comparator: its output flips when the light falls below the level set by the trimmer.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico light theremin: wave your hand over a light sensor to change the note (MicroPython)
from machine import Pin, PWM, ADC
import time
ldr = ADC(26)
speaker = PWM(Pin(15))
LOW_HZ, HIGH_HZ = 200, 1200 # lowest and highest notes
lo, hi = 65535, 0 # learn the bright and dark ends while you play
while True:
v = ldr.read_u16()
lo = min(lo, v)
hi = max(hi, v)
if hi - lo > 2000:
f = LOW_HZ + (v - lo) * (HIGH_HZ - LOW_HZ) // (hi - lo)
speaker.freq(f)
speaker.duty_u16(20000)
else:
speaker.duty_u16(0) # silent until it has seen some light change
time.sleep_ms(20)
Some modules invert DO. Change == HIGH to == LOW in the code.
Normal for a bare piezo; mount it on a small box to resonate.
5 parts: Digital LDR Light Sensor Module – LM393, Piezo Buzzer (passive), 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 ₹511 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.
Generating musical notes with tone(); Thresholds set in hardware vs software.
Ideas that reuse this build: Pico melody player and Amplified theremin. 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.