PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Motors & actuators

Windscreen wiper

EasyBudget $8Python · gpiozero

A servo on GPIO18 is a windscreen wiper. Sweep it smoothly from 0° to 180° over 2 s, then back from 180° to 0° over 2 s, and repeat — starting at 0°.

Power the servo from 5 V; it takes 0.5 ms pulses for 0° and 2.4 ms for 180° (AngularServo(…, min_pulse_width=0.0005, max_pulse_width=0.0024)).

Smoothly means small steps: setting the angle once doesn't work, because the servo would jump there in a fraction of a second. Move a few degrees at a time (e.g. 5° every 1/36 of 2 s). The test checks the angle at 0.5 s (≈45°), 1 s (≈90°), 2 s (≈180°), 3 s (≈90°) and 3.5 s (≈45°).

More in Motors & actuators