Challenge - 5 Problems
gpiozero Hardware Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of gpiozero LED blink code
What will be the output behavior of this code on a Raspberry Pi with an LED connected to GPIO pin 17?
Raspberry Pi
from gpiozero import LED from time import sleep led = LED(17) for _ in range(3): led.on() sleep(0.5) led.off() sleep(0.5) print("Done blinking")
Attempts:
2 left
💡 Hint
Think about what led.on() and led.off() do inside the loop with sleep delays.
✗ Incorrect
The code turns the LED on and off 3 times with half-second pauses, then prints the message. gpiozero's LED class controls the hardware easily with simple methods.
🧠 Conceptual
intermediate1:30remaining
Why gpiozero is easier than RPi.GPIO
Which of these reasons best explains why gpiozero simplifies hardware programming on Raspberry Pi compared to using RPi.GPIO directly?
Attempts:
2 left
💡 Hint
Think about how gpiozero lets you control devices with easy commands.
✗ Incorrect
gpiozero offers ready-made device classes like LED, Button, and Motor with simple methods like on(), off(), and when_pressed, hiding the complexity of pin setup and state management.
🔧 Debug
advanced2:00remaining
Identify the error in gpiozero Button code
What error will this code produce when run on a Raspberry Pi with a button connected to GPIO pin 2?
Raspberry Pi
from gpiozero import Button button = Button(2) if button.is_pressed: print("Button pressed") else: print("Button not pressed")
Attempts:
2 left
💡 Hint
Check the syntax of the if-else statement carefully.
✗ Incorrect
The else statement is missing a colon at the end, causing a SyntaxError before the code runs.
❓ Predict Output
advanced2:00remaining
Output of gpiozero PWMLED brightness code
What will be printed by this code controlling a PWM LED on GPIO pin 18?
Raspberry Pi
from gpiozero import PWMLED led = PWMLED(18) led.value = 0.5 print(f"Brightness: {led.value}") led.value = 1.1 print(f"Brightness: {led.value}")
Attempts:
2 left
💡 Hint
PWMLED value must be between 0 and 1; values outside are clipped.
✗ Incorrect
Setting led.value to 1.1 clips it to 1.0 internally, so the second print shows 1.0.
🧠 Conceptual
expert2:30remaining
How gpiozero improves hardware project reliability
Which statement best explains how gpiozero helps make Raspberry Pi hardware projects more reliable?
Attempts:
2 left
💡 Hint
Think about what happens when a program ends or a button is pressed multiple times quickly.
✗ Incorrect
gpiozero automatically manages debouncing for buttons and cleans up GPIO pins on program exit, reducing hardware errors and improving reliability.