PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Motors & actuators

Second hand

MediumBudget $12Python · gpiozero

A 28BYJ-48 stepper on its ULN2003 board: IN1–IN4 on GPIO17, 18, 27, 22, powered from 5 V. Half-step sequence (IN1..IN4): 1000, 1100, 0100, 0110, 0010, 0011, 0001, 1001 — walking it forwards turns the shaft clockwise (increasing angle). 4076 half-steps make one output turn; from rest, keep to at most one half-step every 2 ms.

Make it the second hand of a clock: at 1 s, 2 s, 3 s, … turn it 6° clockwise (one sixtieth of a turn: 68 half-steps), as fast as allowed. Between ticks, switch all four coils off so the motor stays cool — the rotor stays on its detent, and the next tick carries on the sequence from where it stopped.

The test checks the position about half a second after each tick (68, 136, … half-steps) and that every coil is off then.

More in Motors & actuators