Raspberry Pi practice problem · Projects
Spirit level
MediumBudget $13Python · gpiozero
An electronic spirit level: an MPU-6050 (I²C, 0x68) lying flat on the shelf and three LEDs in a row: left red on GPIO17, level green on GPIO27, right red on GPIO22.
Compute the roll from the accelerometer, roll = atan2(y, z) in degrees (positive when the right side is down), and update at least 5 times a second:
- roll above +3°: only the right LED
- roll below −3°: only the left LED
- otherwise (level within ±3°): only the green LED
The test shelf is level, rolls to +10° at 2 s, to −8° at 4 s and to +2° at 6 s.