Raspberry Pi practice problems
166 Raspberry Pi practice problems in Python, from blinking an LED to full projects: buttons, sensors, displays, motors and I²C/SPI buses. Each one runs in an online simulator with automatic tests.
Create a free account to solve them.
LEDs & PWM
Blinking, fading, patterns and colour: the outputs everything else builds on.
- Easy Two-second glow Switch an LED on for exactly two seconds, once.
- Easy Lighthouse A short flash every two seconds.
- Easy Triple flash Groups of three quick flashes, then a pause.
- Easy Two rhythms Two LEDs blink at different speeds at the same time.
- Easy Upside-down LED An LED that lights when its GPIO goes low.
- Easy Filling up Four LEDs light up one by one, then all clear.
- Easy Staircase Step an LED through four brightness levels with PWM.
- Easy Sunrise Fade an LED up once, slowly, and leave it on.
- Easy Two hundred hertz Set both the frequency and the duty cycle of RPi.GPIO PWM.
- Easy Mixing colours Mix yellow, cyan and magenta on an RGB LED.
- Easy Common anode Drive a common-anode RGB LED, where low means on.
- Medium Theatre chase Every third light of a row marches along, like a cinema sign.
- Medium Gray code Count on three LEDs so that only one light changes at each step.
- Medium Seventy-three Send the number 73 in Morse code, with proper timing.
- Medium Even steps for the eye Gamma-correct PWM steps so they look evenly spaced.
- Medium Crossfade One LED fades out while the other fades in, back and forth.
- Medium Web colours Turn hex colour codes like #FF8000 into PWM duty on an RGB LED.
- Medium Fuel gauge A four-LED bar graph whose last LED shows the fraction with PWM.
- Medium Sawtooth Ramp RPi.GPIO PWM up each second and stay locked to the clock.
- Medium Dice face Seven LEDs laid out like a die show the faces 1 to 6.
- Medium Two LEDs, two wires Two LEDs back to back between two GPIOs, driven by the pins’ difference.
- Hard Scanner with a tail A bouncing scanner light that leaves a dim trail behind it.
- Hard Peak meter A bar graph with a peak dot that holds the recent maximum.
- Hard Colour wheel Sweep an RGB LED smoothly around the hue circle, on time.
- Hard BCD counter Count 00 to 99 in binary-coded decimal on eight LEDs, fast.
- Hard Three-phase glow Three LEDs breathe on sine waves a third of a cycle apart.
Buttons & input
Buttons, switches, keypads and encoders: reading people, debouncing, counting and state.
- Easy Pressed means high Wire a button to 3.3 V and read it with a pull-down.
- Easy Bring your own pull-up A button with an external 10 kΩ pull-up, reported on the console.
- Easy Shutter release Act when the button is let go, not when it is pressed.
- Easy Blink or steady A slide switch selects the LED mode.
- Easy Start and stop A Start button and a Stop button latch a light.
- Easy Ready, set, go Block until the button is pressed, then go.
- Easy Left or right? Tell which way a rotary encoder turns.
- Easy Click the knob Use the encoder's push switch as a toggle.
- Easy Two-hand start An LED lights only while both buttons are held.
- Easy Switch events Report each change of a slide switch, once.
- Medium Short or long One button, two actions: a tap and a long press.
- Medium Double-click Tell a single click from a double click.
- Medium Binary tally Count button presses in binary on three LEDs.
- Medium Fix the bounce A press counter that counts too much: debounce it by hand.
- Medium Encoder cursor A rotary encoder moves a light along four LEDs, wrapping around.
- Medium Step dimmer Up and down buttons step an LED brightness, clamped at the ends.
- Medium Number entry Type a number on the keypad, with backspace and enter.
- Medium Shift and Caps Lock A modifier button changes what another button types.
- Hard Button combination lock Three buttons, a four-press code and an entry timeout.
- Hard Dial safe Dial a three-digit code with a rotary encoder and its push switch.
- Hard Encoder menu Scroll a menu on an LCD with a knob, toggle items with a click.
- Hard Keypad calculator Add and subtract on a 4×4 keypad.
- Hard Tap tempo Tap a rhythm on a button; an LED blinks at that tempo.
- Hard Multi-tap texting Type words on a keypad the old-phone way.
- Hard Tug of war Two players pull a light along five LEDs with their buttons.
Sensors
Light, temperature, distance, motion, sound and moisture: reading the world and acting on thresholds.
- Easy Fahrenheit, please Read a DHT22 and print the temperature in °F.
- Easy Damp alert A blue LED lights while the air is too humid.
- Easy Who goes there? Wait for a PIR to see motion and report when it happened.
- Easy Visitor counter Count PIR motion events, not loop passes.
- Easy Soil check Sort soil-probe voltages into DRY, OK and WET with an ADS1115.
- Easy Imperial ruler Print an ultrasonic distance in whole inches.
- Easy Volt meter Turn an MCP3008 reading into volts.
- Easy Lights on, lights off Report light changes once, not every reading.
- Easy Comfort zone Combine temperature and humidity into one verdict.
- Medium Highs and lows Track the minimum and maximum of a DS18B20.
- Medium Rolling average Smooth a DHT22 with the mean of its last three readings.
- Medium No flicker A night light with two thresholds, so it never flickers at dusk.
- Medium Tank level Turn an ultrasonic distance into a water-tank percentage.
- Medium Baby monitor A light that stays on until three quiet seconds have passed.
- Medium Set the limit A knob sets the temperature at which an alarm LED lights.
- Medium Lost echoes Filter out the readings an ultrasonic sensor gets wrong.
- Medium People counter Count people walking through an ultrasonic beam.
- Medium Dark timer Measure how long each blackout lasts.
- Hard Two-point calibration Calibrate a soil probe in air and water, then read percent.
- Hard Smell in ppm Calibrate an MQ-2 in clean air and convert its analog output to ppm.
- Hard Rate of rise A heat alarm that reacts to how fast it warms, not how hot it is.
- Hard Lux meter Invert an LDR's power law to measure light in lux.
- Hard Desk occupancy Decide whether someone is at the desk, ignoring passers-by.
- Hard Noise dose Add up how long it has been loud, across separate bursts.
- Hard Wait for it to settle Report a probe's temperature only once it has stopped changing.
Displays
Character LCDs, OLEDs, 7-segment digits and LED strips: showing numbers, text and patterns.
- Easy Name badge A 16×2 LCD badge with a centred name.
- Easy Price tag Line up names and prices in two columns on an LCD.
- Easy Lights out Switch an LCD backlight off, keeping the text.
- Easy Flood fill Light every pixel of a 128×64 OLED.
- Easy Error code Show E-42 on a 4-digit display.
- Easy Alarm time Show 07:45 with the colon lit.
- Easy Hand-made letters Spell donE with raw segment bytes.
- Easy Tricolour Paint a blue-white-red flag on a NeoPixel stick.
- Easy Quarter marks Light the 12, 3, 6 and 9 o'clock pixels of a ring.
- Easy Night light A dimmed orange NeoPixel stick.
- Medium Marquee Scroll a message across an LCD, one column every half second.
- Medium Progress bar A loading percentage with a bar of # characters.
- Medium Scoreboard Two buttons keep score on an LCD; first to 3 wins.
- Medium Egg timer Count down from 01:05 in minutes and seconds.
- Medium Segment thermometer A DS18B20 reading in whole degrees on a 4-digit display.
- Medium Scanner One red pixel bounces end to end along a stick.
- Medium Rainbow wheel A spinning rainbow around a NeoPixel ring.
- Medium Filling up Fill an OLED from the top, one 8-pixel band per second.
- Medium Colour picker A button cycles a NeoPixel stick through colours.
- Hard Drinks menu A two-button menu with a cursor and a busy screen on an LCD.
- Hard News ticker A live clock above an endlessly scrolling headline.
- Hard Temperature dashboard One thermometer, three displays: digits, min/max text and a colour bar.
- Hard Chained pixels A stick and a ring on one data line: a progress bar and a spinner.
- Hard Segment scroller Scroll text across four digits, with a pause button.
- Hard Crossfade lamp A button fades a NeoPixel stick smoothly to the next colour.
- Hard Parking meter Coins buy seconds on a countdown display; the stick shows paid or expired.
Motors & actuators
Servos, DC motors, steppers, relays and buzzers: making things move and make noise.
- Easy Wave hello A servo waves back and forth between 60° and 120°.
- Easy Windscreen wiper Sweep a servo smoothly from 0° to 180° and back.
- Easy Reverse gear Run a DC motor backwards at 70 % speed.
- Easy Warm up Wire a relay and a heater yourself and switch it on at 1 s.
- Easy Normally closed A lamp on the relay's NC contact: on until the coil is energised.
- Easy Triple beep Exactly three beeps, then silence.
- Easy Quiet mode PWM duty turns an active buzzer down, not its pitch.
- Easy Gentle on the pin A 1.5 kHz tone with a resistor that keeps the pin under 16 mA.
- Easy Wind back Turn a stepper 45° anticlockwise.
- Easy Hold to pump A water pump runs only while a button is held.
- Medium Kick start A slow speed won't start a motor from rest: kick it first.
- Medium Emergency brake A button brakes a running motor by shorting it through the bridge.
- Medium Second hand A stepper ticks 6° every second and rests its coils in between.
- Medium Jog buttons Two buttons turn a stepper 45° one way or the other.
- Medium Siren A passive buzzer sweeps up from 600 Hz to 1200 Hz once a second.
- Medium Reversing beeper Hold a button to reverse a motor, beeping like a lorry.
- Medium Heat in rhythm Set a heater's power with a slow relay duty cycle.
- Hard Gentle reverse Ramp down, coast, then ramp up the other way on each press.
- Hard Bumper car Slow down near obstacles, brake and beep when too close.
- Hard Note names Turn note names like F#5 into frequencies and play a tune.
- Hard Heat or cool Interlocked heater and fan relays with a dead time between modes.
- Hard Snooze An alarm beeper with a snooze tap and a hold-to-stop.
I²C, SPI, UART & 1-Wire
Talking to chips: ADCs, IMUs, GPS and temperature probes over their buses.
- Easy Who is on the bus? Read a BME280's chip ID register over I²C.
- Easy Two IMUs, one bus Give a second MPU-6050 its own I²C address.
- Easy A thermometer is a file Read a DS18B20 through its 1-Wire sysfs file.
- Easy Satellite clock Print the UTC time from GPS sentences, even before a fix.
- Easy Three bytes over SPI Read an MCP3008 with a hand-built spidev frame.
- Easy Sixteen bits Measure a voltage with an ADS1115 over I²C.
- Easy Cold start Wait for a GPS fix and report the satellites.
- Medium Two's complement Read the MPU-6050's signed temperature register.
- Medium Config register by hand Drive an ADS1115 with raw smbus2 register writes.
- Medium Which way? Turn the GPS course into a compass point.
- Medium Check the CRC Retry DS18B20 reads whose CRC check fails.
- Medium Bus scanner Find every device on the I²C bus by probing addresses.
- Hard Probes on a chain Read every DS18B20 on one 1-Wire bus and report the spread.
- Hard Decode the scratchpad Verify a DS18B20's Dallas CRC and decode its raw bytes yourself.
- Hard Quiet the noise Average many MCP3008 samples to beat conversion noise.
- Hard Calibrate the gyro Measure and subtract an MPU-6050's gyro zero offset.
- Hard Factory calibration Turn raw BME280 counts into °C with its trim registers.
- Hard GPS odometer Add up the distance walked between GPS fixes.
Projects
Several parts working together: small, complete devices.
- Easy Wardrobe light A lamp that lights while the wardrobe door is open.
- Easy Pet feeder A button opens a food flap for 1.5 s.
- Easy Garage stop light Green until the car is close enough, then red.
- Easy Hand dryer A PIR starts a fan that runs on for 2 s.
- Easy Bike light One button cycles off, steady and flashing.
- Easy Tea is ready A probe in the mug lights an LED once tea is drinkable.
- Medium Fridge door alarm Sound a buzzer when the fridge door is left open for 3 s.
- Medium Clap switch Two claps toggle a lamp; one clap does nothing.
- Medium Theremin Wave a hand over a distance sensor to play a pitch.
- Medium Turn signals Left and right indicators for a bike helmet.
- Medium Take a number A deli queue: tickets on one button, "now serving" on a display.
- Medium Bin gauge A distance sensor in the lid shows how full the bin is.
- Medium Spirit level Three LEDs show which way a shelf leans.
- Medium Steam extractor Clear the steam after a shower, with an overrun.
- Medium Meat thermometer Show the roast temperature and beep when it is done.
- Hard Washing machine Wash, rinse and spin, and pause safely when the door opens.
- Hard Vending machine Take coins, sell three snacks, give change back on request.
- Hard Garage door A stepper-driven door that reverses when something is in the way.
- Hard Bike computer Speed and distance from a wheel sensor.
- Hard Aquarium Heater, day/night light and a fish feeder, all on their own schedules.
- Hard Pomodoro timer Work and break countdowns with pause, lights and a chime.
- Hard Quiz show Rounds, a host reset and running scores for three players.
- Hard Smart irrigation Water in pulses, let it soak, and spot an empty tank.
- Hard Bike lock alarm Warn on a bump, sound the alarm if the bike is really moved.