Moving the Hands
For the clock hands, we need continuous rotation and precise positioning.
- Servos: Good for 0-180 degrees. Bad for continuous rotation.
- DC Motors: Good for speed. Bad for precision.
- Stepper Motors: The best of both worlds!
The 28BYJ-48 Stepper
This motor moves in tiny "steps". To make a full circle, we have to tell it to take exactly 2048 steps (depending on the gear ratio).
1#include <Stepper.h>
2
3const int stepsPerRevolution = 2048;
4Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
5
6void setup() {
7 myStepper.setSpeed(10);
8}
9
10void loop() {
11 // Move one minute forward
12 myStepper.step(stepsPerRevolution / 60);
13 delay(60000);
14}Info
We use the stepper for the minute hand because it needs to move precisely 360 degrees over and over again.