Work through the projects in order. Each one introduces a hardware idea, a software pattern, and a small extension that turns the lesson into something of your own.
01 · GPIO FOUNDATIONS
Status Light
Control an LED from Python and learn the basic input/output lifecycle without hiding the hardware behind a large framework.
- Use a resistor and identify GPIO pin numbering.
- Write a clean setup and cleanup path.
- Extend the blink into a timed status indicator.
from gpiozero import LED
from time import sleep
led = LED(17)
for _ in range(5):
led.on(); sleep(0.5)
led.off(); sleep(0.5)Open Python Editor
02 · DIGITAL INPUT
Reaction Timer
Turn a push button into a game. Capture events, measure elapsed time, and separate device callbacks from game state.
- Debounce a button event.
- Use monotonic time for measurements.
- Record and display the best score.
from gpiozero import Button
from time import monotonic
button = Button(4)
started = monotonic()
button.wait_for_press()
print(f"Reaction: {monotonic() - started:.3f}s")Open Python Editor
03 · ANALOG DATA
Room Monitor
Read temperature and humidity from a sensor, validate measurements, and create a useful terminal report.
- Sample on a fixed schedule.
- Handle missing or invalid readings.
- Save timestamped values as CSV.
import csv
from datetime import datetime
reading = {"temperature": 22.4, "humidity": 48}
with open("room.csv", "a", newline="") as file:
csv.writer(file).writerow([datetime.now(), *reading.values()])Open Python Editor
04 · DISPLAY OUTPUT
Desk Dashboard
Build a small status screen with an OLED or LED matrix. Practice layout, refresh cycles, and readable information design.
- Render a clock and sensor summary.
- Refresh only when data changes.
- Keep display code independent from sensors.
def format_dashboard(time_text, temperature):
return f"{time_text}\nTemp: {temperature:.1f} C"
print(format_dashboard("09:30", 22.4))Open Python Editor
05 · NETWORKING
Local Sensor API
Expose readings over a small HTTP endpoint so another device can request the latest state on your local network.
- Define a compact JSON response.
- Validate request paths and errors.
- Keep secrets and device settings out of source code.
from http.server import BaseHTTPRequestHandler
class SensorHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/api/room":
self.send_response(200)
self.send_header("Content-Type", "application/json")Open Python Editor
06 · AUTOMATION
Plant Care Assistant
Combine moisture readings, a pump relay, and a safety timeout into a system that waters a plant only when needed.
- Set a dry threshold with hysteresis.
- Prevent a stuck relay from running forever.
- Log every automatic action for review.
DRY_LIMIT = 35
MAX_PUMP_SECONDS = 4
if moisture < DRY_LIMIT:
pump.on()
sleep(MAX_PUMP_SECONDS)
pump.off()Open Python Editor
07 · CAPSTONE
Home Environment Station
Bring the course together in a reliable station with sensors, display, local API, and a simple alert policy.
- Design modules for hardware, storage, and presentation.
- Recover safely from sensor or network failure.
- Document the circuit, setup, and operating limits.
def collect_reading(sensor, clock):
try:
return {"time": clock(), **sensor.read()}
except OSError as error:
return {"error": str(error)}Open Python Editor