rAs Kids All courses
Robotics with Python ยท Module 2 of 8
๐Ÿชจ No device needed

State Machines with Bottle Caps

A machine is always in exactly one state, and only certain events can move it to another.

[IDLE] โ†’๐Ÿ’ง [PUMPING] โ†’โš ๏ธ [FAULT]
Three bottle caps laid on the ground with chalk arrows between them, each arrow labelled with what causes the move.

๐ŸŽ’ What you need

โœ‹ Do this

  1. Choose a borehole pump controller. List its states on separate caps: IDLE, PUMPING, TANK FULL, FAULT.
  2. Lay the caps out with space between them and draw an arrow for every legal move. Label each arrow with its trigger: 'button pressed', 'float switch high', 'motor too hot'.
  3. Now find an illegal move. Can you go from IDLE straight to TANK FULL? No. Cross that arrow out โ€” the arrows you refuse to draw are what makes the machine safe.
  4. Play it: a friend calls out events at random and you physically move a stone from cap to cap. Any event with no arrow is simply ignored.
  5. Add the awkward one: what happens if power fails mid-pump and comes back? Which state should it wake in? Argue it, then decide and draw it.
  6. Copy the finished diagram onto paper. That drawing is a genuine engineering document and it is what you would code from.

๐Ÿ’ก Why it works

State machines are how real controllers stay predictable, from washing machines to lift doors to mobile-money flows. The value is not the states, it is the transitions you deliberately do not allow โ€” that is how you guarantee a pump cannot run dry or a lift cannot open between floors. Load-shedding makes the power-fail transition a genuinely important design question here, not a hypothetical one.

๐Ÿ”ฅ Challenge

Model something with at least six states โ€” a matatu fare collection, a maize mill, a phone charging from a solar panel. Find one transition everybody forgets, then add it.

๐Ÿ“– New words

stateone distinct situation the system can be in at a moment
transitiona permitted move from one state to another
eventthe thing that happens and triggers a transition
๐Ÿ”
State Setter

Tap when you have finished this module.