All paths

Python on the Pi's pins

Drive real parts from Python with gpiozero: LEDs and PWM, buttons and events, buzzer signals and tunes, servos, a sonar and a motion sensor, then build a desk alarm as a state machine.

Raspberry Pi 4 Model BFree7 lessons5 h3 chapters1,445 XPCoding · Beginner+100 XP

0 of 7 done

What you will build

2 projects, built step by step

7 lessons in 3 chapters, about 5 hours on a simulated Raspberry Pi 4 Model B. Free, in your browser, every step checked by the simulator.

Chapter 1 project

Buzzers and tunes

Make ship alarms with gpiozero: a Buzzer on and off, beep() in the background, Morse code sent from a dict, the math that turns note names into frequencies, and a rising tune on a TonalBuzzer, with the circuit's LED standing in for the buzzer so you can see every signal.

Open it in the simulator
Chapter 2 project

Motion sensor

Watch an airlock with a PIR sensor: wait for motion and stillness, switch to when_motion events so the program is free, log every visit with a time, and add a cooldown so one person does not raise ten alerts.

Open it in the simulator
The map

Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

Outputs

Pins high and low, PWM, and signals you can see and hear.

  1. Open190 XP

    LEDs and PWM

    Drive the launch pad lights with gpiozero: on and off, a countdown that blinks, blink() running in the background, PWM for brightness, the duty cycle worked out in milliseconds, and pulse() for a breathing engine glow.

    0 of 6 steps

  2. Locked165 XP

    Buttons and events

    Read a pushbutton three ways: polling is_pressed in a loop, counting presses by watching for the change, and letting gpiozero call your functions with when_pressed and when_held; then build a reaction timer.

    0 of 5 steps

  3. ProjectLocked330 XP

    Buzzers and tunes

    Make ship alarms with gpiozero: a Buzzer on and off, beep() in the background, Morse code sent from a dict, the math that turns note names into frequencies, and a rising tune on a TonalBuzzer, with the circuit's LED standing in for the buzzer so you can see every signal.

    0 of 5 steps

4 questions, graded as you go.
Chapter 2

Motion and sensing

Pulses that set an angle, echoes that measure, and heat that moves.

  1. Locked140 XP

    Servos

    Aim an antenna dish with a hobby servo: Servo min and max, why its default pulses miss this servo's range, AngularServo with the right pulse widths, angles typed in the Serial Monitor and checked first, and a sweep that ends with detach().

    0 of 4 steps

  2. Locked165 XP

    Distance sensor

    Build a sonar with an HC-SR04 and gpiozero's DistanceSensor: read the distance, move the target and see it change, light a warning when something comes within 20 cm, draw a bar graph that grows as it nears, and work out the echo times from the speed of sound, in air and under the sea.

    0 of 5 steps

  3. ProjectLocked280 XP

    Motion sensor

    Watch an airlock with a PIR sensor: wait for motion and stillness, switch to when_motion events so the program is free, log every visit with a time, and add a cooldown so one person does not raise ten alerts.

    0 of 4 steps

4 questions, graded as you go.
Chapter 3

Project

Sensing, timing and state in one build: the desk alarm.

  1. Locked175 XP

    Project: a desk alarm

    The finale: a drawer alarm as a state machine. Arm it from the Serial Monitor, let the drawer switch trigger an entry delay, sound a flashing siren when time runs out, stand it down with a secret knock on the same switch, and keep a timed log of what happened.

    0 of 6 steps

3 questions, graded as you go.
Syllabus

Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

Outputs

  1. LEDs and PWMDrive the launch pad lights with gpiozero: on and off, a countdown that blinks, blink() running in the background, PWM for brightness, the duty cycle worked out in milliseconds, and pulse() for a breathing engine glow.
  2. Buttons and eventsRead a pushbutton three ways: polling is_pressed in a loop, counting presses by watching for the change, and letting gpiozero call your functions with when_pressed and when_held; then build a reaction timer.
  3. Buzzers and tunesMake ship alarms with gpiozero: a Buzzer on and off, beep() in the background, Morse code sent from a dict, the math that turns note names into frequencies, and a rising tune on a TonalBuzzer, with the circuit's LED standing in for the buzzer so you can see every signal.
Chapter 2

Motion and sensing

  1. ServosAim an antenna dish with a hobby servo: Servo min and max, why its default pulses miss this servo's range, AngularServo with the right pulse widths, angles typed in the Serial Monitor and checked first, and a sweep that ends with detach().
  2. Distance sensorBuild a sonar with an HC-SR04 and gpiozero's DistanceSensor: read the distance, move the target and see it change, light a warning when something comes within 20 cm, draw a bar graph that grows as it nears, and work out the echo times from the speed of sound, in air and under the sea.
  3. Motion sensorWatch an airlock with a PIR sensor: wait for motion and stillness, switch to when_motion events so the program is free, log every visit with a time, and add a cooldown so one person does not raise ten alerts.
Chapter 3

Project

  1. Project: a desk alarmThe finale: a drawer alarm as a state machine. Arm it from the Serial Monitor, let the drawer switch trigger an entry delay, sound a flashing siren when time runs out, stand it down with a secret knock on the same switch, and keep a timed log of what happened.
Kits

Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.

See every kit
Questions

About Python on the Pi's pins

Is Python on the Pi's pins free?

Yes. All 7 lessons of Python on the Pi's pins are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Raspberry Pi 4 Model B?

No. Every lesson runs on a simulated Raspberry Pi 4 Model B with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Python on the Pi's pins take?

About 5 hours: 7 lessons in 3 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Buzzers and tunes and Motion sensor.

Where do I start?

With "LEDs and PWM", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.