By Kevin McAleer, 5 Minutes
Page last updated November 20, 2026

On and off is only the start. This lesson is about everything in between: brightness, pitch and position.
A pin can only be fully on or fully off. But if you switch it on and off very fast, an LED looks dimmer. Spend more of the time on and it looks brighter. That trick is called PWM, pulse width modulation.
Two blocks control it:

This uses a new loop, for each item in list. It runs the blocks inside once for every value, and puts each value in the variable level.
range(0, 101, 5) counts 0, 5, 10 and so on up to 100. It stops before 101, which is why it isn’t 100duty_u16() wants a number from 0 to 65535, not a percentage. So the block does the sum for you: level * 65535 / 100That second line is a good example of why blocks are a kind way to start. The block says 50 %. The Python shows you what the Pico really needs.
A buzzer makes a note when you switch it on and off at the note’s frequency. 440 Hz is the A that orchestras tune to.

buzzer_16.tone(440, 200) plays 440 Hz for 200 millisecondsbuzzer_16.stop() is the silence buzzer blockThe simulator has no speaker, but you can watch GP16 working in the board view. On a real Pico, connect a piezo buzzer between GP16 and GND.
Some notes to play with:
| Note | Frequency (Hz) |
|---|---|
| C | 262 |
| D | 294 |
| E | 330 |
| F | 349 |
| G | 392 |
| A | 440 |
A servo is a motor that turns to an angle you choose and holds it. Robot arms, grippers and steering all use them.

In the box, the console lists each move as a line starting SNK SERVO. That is the simulator reporting the angle the servo has been told to go to.
Servos are driven by PWM too. The Servo helper turns your angle into the right pulse, so you only think in degrees.
This program uses the other wait block, wait 1 seconds, which writes time.sleep(1).
Powering servos: a small servo such as an SG90 can run from the Pico’s VBUS pin for testing. Anything bigger needs its own power supply, with its ground joined to the Pico’s ground.
Problem: The LED flickers instead of fading. Solution: Set the frequency to 1000 Hz before setting the power. Why: At a low frequency your eye can see each flash.
Problem: The servo twitches or the Pico resets. Solution: Power the servo from a separate supply, and join the grounds. Why: Servos draw more current than the Pico’s 3.3V pin can give.
Problem: A warning badge appears on my buzzer blocks. Solution: Nothing to fix if they are meant to share a pin. Why: Snakie flags any two blocks on one pin, in case it was a mistake.
Quick quiz 1 of 3
What does PWM change to make an LED dimmer?
Quick quiz 2 of 3
What does buzzer_16.tone(440, 200) do?
Quick quiz 3 of 3
Why does range(0, 101, 5) end at 101?
range() never includes its stop value.
You can use the arrows ← → on your keyboard to navigate between lessons.
Comments