Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsA servo turns to an angle set by the length of a pulse sent 50 times a second: 0.5 ms for one end, 2.5 ms for the other. The Pico's PWM makes those pulses and its analog input reads the knob, so this short program teaches PWM, analog input and mapping one range onto another.
Tick anything you already have and the total updates.
Small hobby servo that turns to any angle from 0 to 180° on command.
A 10 kΩ knob that works as a voltage divider, giving an analog value you can map to anything.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico servo controlled by a knob (MicroPython)
from machine import Pin, PWM, ADC
import time
servo = PWM(Pin(15))
servo.freq(50) # servos expect a pulse every 20 ms
knob = ADC(26)
def angle_to_duty(angle):
us = 500 + angle * 2000 // 180 # 0.5 ms = 0 degrees, 2.5 ms = 180 degrees
return us * 65535 // 20000
last = -1
while True:
angle = knob.read_u16() * 180 // 65535
if abs(angle - last) > 1: # ignore tiny wobbles in the reading
servo.duty_u16(angle_to_duty(angle))
last = angle
print(angle)
time.sleep_ms(20)
Power the servo from a separate 5 V supply and join the grounds; add a 470 µF capacitor across the servo supply.
The wiper is on an outer pin. Move the signal wire to the middle leg.
5 parts: TowerPro SG90 9g Micro Servo (180°), 16mm Rotary Potentiometer 10kΩ (Linear), 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 ₹585 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.
PWM pulses and servo control; Voltage dividers and analogRead().
Ideas that reuse this build: Arduino servo knob and Servo tester. 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.