State Machine Lesson Plan
CS Core: Systems & Logic Grades 4–5 • 75 Minutes (or 2 × 40m Blocks)
State Machine Maze: Teacher Lesson Plan
Teaching students how software tracks internal modes, handles user inputs, and enforces system rules.
CSTA Standard
1B-AP-10 & 1B-AP-15
Control & System State
Essential Question
How do computers remember what mode they are in, and how do rules stop users from breaking software?
Student Learning Targets
- • Identify & Define States: Explain that a "state" is a discrete condition or operating mode (e.g., Idle, Playing, Paused).
- • Diagram Transitions: Map cause-and-effect transitions using directed nodes (circles) and labeled event arrows.
- • Defend Against Bugs: Identify illegal transitions (e.g., jumping while frozen) and formulate defensive rules.
Architect Vocabulary (Anchor Terms)
State (Node)
The current condition or mode of the machine. Only one active at a time.
Event / Trigger
An input or signal (button tap, timer, collision) that causes a change.
Transition (Arrow)
The authorized path moving the system from an origin state to a destination state.
Illegal Move (Bug)
An event attempted in a state that has no legal path (e.g., pause during loading).
1
Hook & Kinesthetic Game: The Human Turnstile (15 Mins)
Whole Class Unplugged
Setup: Draw two chalk/tape circles on the carpet: LOCKED and UNLOCKED. Choose a student volunteer to be the "Subway Gate Robot" standing in LOCKED.
Teacher Facilitation Steps:
- Class calls out "PUSH!". Gate says: "Access Denied, arm is rigid." (No transition).
- Class calls out "SWIPE CARD!". Gate transitions and steps into UNLOCKED.
- Class calls out "PUSH!". Gate rotates and steps back into LOCKED.
Key Debrief Question:
"Why did the PUSH command do nothing the first time, but work the second time? Because computers react to inputs based on what STATE they are in!"
2
Direct Instruction: Deconstructing UI & Games (20 Mins)
Slides & Guided Modeling
Project the State Machine Maze Slides. Deconstruct everyday tech systems into finite states:
App Login Screen
Logged Out → Checking Password → Success (Home) OR Error (Locked Out after 3 tries).
Game Character
Idle → Running → Jumping → Falling → Respawning. What happens if you press Jump while in mid-air?
Smart Microwave
Door Open → Ready/Idle → Cooking → Paused. Guardrail: Cannot start magnetron while door is open!
The State Machine Maze • Computer Science Unit Plan Page 1 of 2
Instructional Guide Continued
Studio Implementation, Bug Hunts & Differentiation
Part 3 & 4 Sequencing
3
Project Studio: The System Architect Challenge (25 Mins)
Paired or Solo Work
Hand out the State Maze Project Packet. Students choose one system theme to diagram:
Option A: Arcade Boss Battle
States: Patrolling, Enraged (low HP), Shielded, Stunned, Defeated.
Option B: Smart Soda Machine
States: Awaiting Coins, Selecting Drink, Dispensing, Refunding Change.
Option C: Mars Rover Autopilot
States: Solar Charging, Navigating, Drilling Rock, Storm Hibernation.
Teacher Circulating Prompts:
- "Point your finger to the start node. When this button is pressed, where does your finger slide next?"
- "Can the player go directly from 'Solar Charging' to 'Drilling Rock'? If not, make sure there is no arrow!"
- "What is the guardrail rule if someone presses Refund while the can is falling?"
4
Peer Bug Hunt & Stress Testing (15 Mins)
Peer Review & QA Testing
Students swap diagrams with a "Quality Assurance (QA) Tester" partner. Partners place a token (eraser or counter) on the starting state and attempt to break the system:
The Chaos Input Test
The tester calls out fast, chaotic button presses. The architect must physically trace valid arrows or declare "INPUT REJECTED" using the state machine's logic.
Bug Log Reflection
If a partner gets stuck in an infinite loop or trapped in a dead-end state with no exit arrows, the architect documents the bug and redraws the missing transition.
Tiered Scaffolding
Support (Striving Learners):
Provide pre-cut circular state nodes (Idle, Active, Done) and pre-written arrow labels to physically arrange before drawing ink.
Extension (Advanced Coders):
Add an Interrupt/Timeout State (e.g., "Inactive 60s → Sleep Mode") or conditional branch logic (e.g., [If Coin ≥ $1.50]).
Common Misconceptions
Misconception: "A machine can be in two states at once (e.g., Running AND Jumping)."
Clarification: By definition, a simple state machine is in exactly one active mode at any millisecond.
Misconception: "Arrows can point both ways without labels."
Clarification: Transitions are one-way streets. Going back requires its own explicit trigger event.
Lesson Preparation Checklist
Project slides, print 1 packet per student, print scoring rubric for testing teams, gather tokens/counters.
Packets Ready Slides Ready
The State Machine Maze • Computer Science Unit Plan Page 2 of 2
State Machine Maze Slides
Computer Science Studio Systems & Computational Logic
FSM // ARCHITECT v1.0
Mission Briefing
The State Machine Maze
How software remembers where it is, reacts to your inputs, and follows strict rules to prevent bugs!
A State [START]
──( Event Trigger )──►
B State [ACTIVE]
Concept 01 // Fundamentals
What is a "State"?
A State is the specific mode or status a machine is in right now.
Rule of Thumb: A machine can only ever be in ONE state at a time!
Traffic Light
States: RED, YELLOW, or GREEN. It can never be Red AND Green together!
Game Hero
States: IDLE, RUNNING, JUMPING, or STUNNED.
Microwave
States: DOOR OPEN, READY, or COOKING.
Concept 02 // Anatomy
The 3 Parts of a State Diagram
1
The State Node
Drawn as a CIRCLE. Shows where the software is resting right now (its current mode).
( PAUSED )
2
The Trigger Event
The INPUT or SIGNAL that happens (a button press, a clock timer, or collision).
[ Press Spacebar ]
3
The Transition
Drawn as a DIRECTED ARROW. The authorized path connecting one state to the next!
State A ────► State B
Transitions are one-way streets. If you want to return, you need another arrow! Rule: A → B ≠ B → A
Case Study // App Security
How Apps Think: The Login Screen
LOGGED OUT
Waiting for user to enter username & password.
Submit Info →→→
VERIFYING
Checking credentials against the server database.
Match Found →
LOGGED IN (Home)
Wrong 3x →
ACCOUNT LOCKED
Why it matters: Without this state machine, a hacker could simply type random letters and skip straight to the Home Screen!
Defense // Guardrails
The "Illegal Move": Stopping Glitches
State Maze Project Packet
CS System Architect Packet
State Machine Maze Blueprint
ENGINEERING LOG
Lead Architect Name: _________________________
Date: _________________
Class / Section: ___________
Architect Mission Objective
Your mission is to engineer an unbreakable state machine for a piece of interactive software. You will define the system's operational modes (states), map every legal transition path with arrow triggers, and build a guardrail rule to prevent illegal moves and glitches!
1 Select Your System Architecture (Check One)
Select 1 scenario to blueprint
Arcade Boss Battle
Design the combat AI for a video game boss. Modes: Patrol, Attack, Enraged, Stunned, Defeated.
Focus: Health triggers & timers
Smart Soda Machine
Control coin inserts, drink selections, inventory alerts, dispensing cans, and refund levers.
Focus: User inputs & money logic
Autonomous Rover
Plan the autopilot modes for a planetary rover: Solar Charging, Driving, Drilling, Storm Sleep.
Focus: Sensor inputs & safety modes
2 System State Inventory (Catalog 4 to 5 States)
Identify discrete modes
Write down each state (mode) your machine can be in. Mark which state is the START state!
| Node | State Name (Mode) | What is the system doing in this state? | Start? |
|---|
| S1 | | | [ ] |
| S2 | | | [ ] |
| S3 | | | [ ] |
| S4 | | | [ ] |
| S5 | | | [ ] |
3 Event & Trigger Bank
List 4 possible inputs/signals
What causes the system to change states? (e.g., "Insert $1.00", "Health < 20%", "Door Closes", "Timer Expired").
Trigger 1:
Trigger 2:
Trigger 3:
Trigger 4:
State Machine Maze • Student Project Guide Turn to Page 2 for Blueprint Diagram →
Step 4 & 5 • Blueprint Canvas
State Machine Node Diagram & Rules
START NODE RULE Draw double ring around Start!
4 Diagrammatic State Maze Canvas
Draw circular nodes & labeled directed arrows
// ARCHITECT DRAFTING SURFACE DIAGRAM KEY: [ ○ State Node ] ──( Event Trigger )──► [ ○ Next State ]