Project 11 — The Marble Counting Machine
Text written by Claude Fable 5 (claude-fable-5).
Project 11 — The Marble Counting Machine
The one idea: a machine with no brain can count. Every marble that rolls past nudges the invisible eye, and a lit dot hops one step along a row of ten LEDs. The machine never loses track, never gets bored, never counts the same marble twice.
The new part is the CD4017, a chip as cheap and as classic as the 555: ten outputs, exactly one high at a time, and every clock pulse moves the “on” to the next one. Wire ten LEDs to it and you have a dot that steps 0…9 — a counting machine the child can see think.
How does a 16 mm marble use a 5 mm slot? It doesn’t go through it — it flicks a flag that does. A little cardboard flag on a straw hinge hangs into the marble’s path; the flag’s top tab rests inside the opto slot. A marble rolls by, tips the flag, the tab swings out of the slot, the beam blinks through — one count — and the flag swings back to block it again. (If you’d rather skip the mechanics: a wide DIY light gate as in Project 8 across the track works too. But the flag is honestly the fun part.)
What you need
- 4×AA battery holder (6 V)
- A slotted optointerrupter + 220 Ω and 10 kΩ (the Project 7 eye)
- A CD4017 decade counter (buy two if you want the 0–99 extension)
- Ten LEDs — mixed colours encouraged — plus one 470 Ω resistor (really, just one; trick below) and a pushbutton
- 10 kΩ + ~10 µF for calming the flag’s signal
- Marble run: a cardboard tube cut in half, a book ramp with cardboard rails, or the real toy if you own one — plus marbles
- Cardboard, a straw + skewer (or just a tape hinge) for the flag
Build it — stage 1: the flag mechanism
- Cut a cardboard flag shaped like a lowercase T rotated: a tall tab on top, a wide paddle at the bottom.
- Hinge it just above the track — skewer through a straw taped across two supports, flag taped to the skewer, or simply a floppy tape hinge — so the paddle hangs into the marble’s path and the top tab sits inside the opto slot.
- Mount the opto (blu-tack) so that at rest the tab blocks the beam, and a rolling marble tips the paddle enough to swing the tab clear.
- Tune until a marble reliably makes the flag do one clean flip-flop: tip, swing back, settle. A small blob of blu-tack low on the paddle makes it bottom-heavy so it settles fast instead of waggling.
This is 15 minutes of pure mechanical play and it’s where the child does the engineering. Marble in, flag flips — you can already see the event; now we’ll make the circuit see it.
Build it — stage 2: the eye and the counter
The eye, wired so that light = HIGH (the Project 8 way up): opto LED side + → 220 Ω → LED → GND; phototransistor collector → +, emitter → the signal node, node → 10 kΩ → GND. At rest (tab in slot) the node sits LOW; each marble makes a brief HIGH pulse. Add the calming filter: 10 kΩ in series from the node to the 4017’s clock pin, and 10 µF from that pin to GND — it irons out any last flag wobble so one marble is one count.
The CD4017 (16-pin DIP; pin 1 is left of the notch, as always):
- Pin 16 → +, pin 8 → GND.
- Pin 13 (clock inhibit) → GND. Pin 15 (reset) → GND through 10 kΩ, and through the pushbutton to + — pressing it sends the dot home to zero.
- Pin 14 (clock) ← the filtered signal node.
- The ten outputs, in counting order, are pins 3, 2, 4, 7, 10, 1, 5, 6, 9, 11 (yes, scrambled — chip-internal layout reasons; label them 0–9 with a marker on masking tape). LED anode to each output.
- The one-resistor trick: since only one output is ever high, all ten LED cathodes join into one rail → single 470 Ω → GND.
Press reset: LED 0 lights. Roll a marble: the dot hops to 1. Roll nine more and watch it walk the whole row and wrap around to 0 — the machine counts in circles, just like the ones-digit of a car’s odometer.
What to say to the child
“Let’s count the marbles — but not us: the machine will. Every marble that rolls past bumps the little flag, the flag uncovers the secret light for a blink, and that blink tells the chip: one more! Watch the light hop along… three… four… five. It never forgets and never counts double. Try to trick it! Roll two marbles almost together — did it catch both? Now roll ten and watch what happens after nine… it goes back to zero, just like when you count on your fingers and run out — you’d need another hand. Want to give the machine another hand?”
For you — the physics
- Level vs. edge. The alarm (Project 7) cared about a level — is the beam blocked right now? A counter cares about edges — the moment the signal goes low→high. Same wire, different question, and the distinction (state vs. event) runs through all of digital design and half of experimental physics (threshold detectors, particle counters — a Geiger counter is this project with ionising radiation for marbles).
- Debouncing. The flag can oscillate after a hit, and each swing past the beam would be an extra edge. The series RC (10 kΩ · 10 µF ⇒ τ = 0.1 s) low-passes those flutters into one smooth rise, and the 4017’s Schmitt-trigger clock input turns that slow rise into exactly one clean internal edge. Mechanical switches need the same treatment — every keyboard key you’ve ever pressed was debounced for you.
- What’s inside the 4017: five flip-flops in a ring (a Johnson counter), each the same “one bit of memory” the child latched in Project 8, plus decoding so exactly one of ten outputs is high. Counting is just remembering, repeatedly.
- Carry is how numbers scale. Pin 12 (carry-out) goes high once per full lap — a second 4017 clocked from it counts tens. Two chips: 0–99. That cascade is positional notation, built from parts; the odometer analogy is exact.
Try it with the Arduino — a real scoreboard
The same filtered signal into a digital pin, count rising edges, print the total — to the Serial monitor or whichever display you have at hand. The Arduino adds what the 4017 can’t: arithmetic. Marbles per minute, time gaps between marbles (“which ramp height makes them come fastest?”), a beep at a target count. Ten lines of code; the sensor side doesn’t change at all.
Try next
- Count to 99: second 4017 clocked by pin 12, ten more LEDs — tens and ones, and the child watches carry happen physically at every tenth marble.
- Lap counter: aim Project 8’s light gate at a circular track and the same counter counts laps instead of marbles.
- Race the machine: child counts a fast pour out loud, machine counts silently, compare. (The machine wins. This is oddly formative.)
- LED chaser toy: disconnect the eye and clock pin 14 from the Project 6 555 slowed way down (~5 Hz) — the dot runs by itself. Congratulations: Knight Rider.
← Back to Read Me First.