Source: https://mokxi.com/teachers/plans/build-marble-machine
Updated: 2026-11-19

Lesson plan

# Build a marble machine lesson plan

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

3 chapters, 6 lessons, about 6 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## Objectives and materials

### By the end, students can

- The stepper’s steps, speed and stall, and a gate that follows a pattern.
- Every marble counted once, on an interrupt, and shown on the strip.
- A jam alarm tied to the lift’s speed, then the endless run.

### Materials for the whole unit

- Addressable RGB LEDs
- Arduino Uno R3
- Hobby servo
- Photo interrupter, slot
- Stepper motor, 28BYJ-48 with ULN2003

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 2 h 5 min

## Lift and gate

The stepper’s steps, speed and stall, and a gate that follows a pattern.

Lesson | Time | What students do

A lift A 28BYJ-48 stepper turns a screw that lifts a marble a turn. Move it by steps, work out 2048 steps a turn, time the steps from rpm, stall it by asking too much, and ramp it up to beat the stall. | 75 min

- The machine
- 2048 steps a turn
- Speed is time between steps
- The coil pattern
- Too fast, and it stalls
- Ramp it up

Gates A servo gate at the top sends each marble down track A or B. Follow a route pattern, change it from the Serial Monitor, and make a pattern the machine starts with. | 50 min

- A marble arrives
- The gate swings
- A route pattern
- A pattern it starts with

### Materials

- Addressable RGB LEDs
- Arduino Uno R3
- Hobby servo
- Photo interrupter, slot
- Stepper motor, 28BYJ-48 with ULN2003

### Check for understanding

Each student finishes "Gates" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "A pattern it starts with".

Chapter 2. About 1 h 55 min

## Count and show

Every marble counted once, on an interrupt, and shown on the strip.

Lesson | Time | What students do

Counting marbles A marble crosses the beam in a few milliseconds. Count on an interrupt so none is missed, debounce a wobbling marble, break the debounce to see why it matters, and read the rate. | 65 min

- Blocked is HIGH
- On an interrupt
- A wobbling marble
- Without the debounce
- The rate

Light effects Eight WS2812 LEDs on one wire: a bar that fills with each marble in the color of its track. Read the strip, fill it faster, and keep the current in check. | 50 min

- One wire, eight LEDs
- The color of the track
- A faster bar
- All of them

### Materials

- Addressable RGB LEDs
- Arduino Uno R3
- Hobby servo
- Photo interrupter, slot
- Stepper motor, 28BYJ-48 with ULN2003

### Check for understanding

Each student finishes "Light effects" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "All of them".

Chapter 3. About 1 h 55 min

## Run forever

A jam alarm tied to the lift’s speed, then the endless run.

Lesson | Time | What students do

Jam detection A stepper never knows it is stuck. The counter does: no marble for a turn and a half means a jam. Catch one, see it in red, clear it, and tie the timeout to the lift’s speed. | 65 min

- No marble, no news
- See it in red
- Clear it
- The timeout follows the speed
- A patient alarm

Project: an endless run Run the machine for real: the lift on, marbles round and round, stats as it goes. Then add a lap of honor every ten marbles and a count for each track. | 50 min

- Round and round
- A lap of honor
- Count each track
- Show it

### Materials

- Addressable RGB LEDs
- Arduino Uno R3
- Hobby servo
- Photo interrupter, slot
- Stepper motor, 28BYJ-48 with ULN2003

### Check for understanding

Each student finishes "Project: an endless run" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Show it".

Your class

## Teach this unit as a class

Start a class from this course and its 6 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
