Build a pinball table
A complete home-built pinball controller on a Mega, and a five-lesson course that builds it one stage at a time.
The finished table
Pinball table is the whole controller under a real playfield, wired the way you would wire it at home:
- Flippers: two red arcade buttons drive two hobby servos. A full-size table snaps its flippers with solenoids; servos are the friendly place to start, and the code that reads the buttons is the same.
- START and LAUNCH: white starts a game, green stands in for the plunger.
- Targets and bumpers: three standup targets and two pop bumpers, each a microswitch with NO on a pin and COM on ground.
- Kicker: a 12 V solenoid fired for 30 ms through an IRLZ44N MOSFET, with a 1N4007 diode across the coil.
- Drain: a photointerrupter. Push its card into the slot when the ball gets past you.
- Backbox: the score on a TM1637, sixteen WS2812 lamps and a piezo for the tunes.
Every switch uses the chip's own pull-up, so pressed reads LOW and no switch needs a resistor.
How a game goes
The sketch is a state machine. At any moment the table is in one state, and the state decides what each switch means:
- Attract: the lamps run a rainbow and the display cycles through the last score, the high score and its initials. Press START.
- Launch: the shooter lane arrows chase. Press LAUNCH.
- Play: targets score 50, bumpers score 10 and fire the kicker. Light all three targets for a 200 point bonus and a step up the multiplier, to 5x at most. Pass 2,500 for an extra ball.
- Drain: lose the ball and the multiplier resets. A drain in the first six seconds after a launch is saved and the ball comes back.
- Game over: three balls a game. Beat the high score and you enter your initials: the flipper buttons pick a letter and START keeps it.
The high score and initials live in the Mega's EEPROM, so they survive a reset of the board. A fresh Run starts the chip erased, as a new board would be.
The course
Build a pinball table gets there in five lessons, each on the same layout with more of the parts in place:
- Flippers that answer: buttons, pull-ups and servos.
- Targets and a score: edges, debouncing and the TM1637.
- A bumper that kicks: a MOSFET, a coil and the diode that protects it.
- Lights and sound: attract mode and a tune that never makes the lights wait.
- The whole table: the state machine, ball save and the saved high score.
Every step is checked against the running circuit, so you always know when it works.