Lessons and the learning game

Build a marble machine

A 28BYJ-48 lift, a servo gate that routes, a debounced marble counter, a WS2812 count bar and a jam alarm, for a marble machine that runs forever.

What the course teaches

Six lessons in three chapters, at /learn/path/build-marble-machine on /learn. The learner is the marble: a card pushed through the photointerrupter's slot is a marble rolling through the beam.

  • Lift and gate. The 28BYJ-48 takes 2048 full steps a turn (32 at the rotor, 64:1 gearbox). The learner moves it by steps, works out the step time from rpm (2441 us at 12 rpm), watches the two-coil pattern, stalls it at 20 rpm from a standstill and beats the stall with a ramp. A servo gate follows a route pattern, a small state machine.
  • Count and show. Marbles counted on interrupt 0, a 5 ms debounce for a wobbling marble (and what happens without it), the rate, and a WS2812 bar in the color of the last track.
  • Run forever. No marble for a turn and a half means a jam: the lift stops, the strip turns red, and the timeout follows the lift's speed. The project adds a lap of honor and a count for each track.

The circuit

Part Wiring
28BYJ-48 on its ULN2003 board IN1 to IN4 on pins 8 to 11, its own 5 V
KY-010 photointerrupter S on pin 2 (interrupt 0)
Servo gate signal on pin 6, its own 5 V
WS2812 strip of 8 DIN on pin 5, its own 5 V

The sketch is marbrun, also in the Uno's Examples menu. It takes lift on, lift off, rpm N, steps N, route ABB and stats.

Troubleshooting

  • The stepper buzzes and does not turn. It was asked to start faster than about 17 rpm. Lower the rpm or set RAMP to true.
  • One marble counts twice. The debounce is off: DEBOUNCE_MS should be about 5.
  • The lift stops with a JAM. No marble reached the beam for JAM_TURNS turns. Send one through to clear it, then lift on.
  • The strip is all red. That is the jam signal.

Paths and lessons explains how a course, its checkpoints and its chapter quizzes work.