🧠 What Is a Finite State Machine?
Imagine you’re playing a simple video game character — say, Mario.
Mario can be in one of a few states:
- Standing
- Jumping
- Running
At any moment, he’s doing just one of these things. But when you press a button, he changes to another state — maybe from standing to jumping.
That’s the basic idea of a Finite State Machine (FSM):
a digital system that can be in one state at a time, and it changes states when certain inputs are received.
⚙️ In Digital Logic Terms
A Finite State Machine is a model used to describe the behavior of sequential circuits — circuits that depend not only on current inputs but also on past states (stored in flip-flops).
In simple words:
FSM = Logic circuit that moves from one condition (state) to another based on input signals and clock pulses.
So, FSMs are like the brains behind counters, registers, vending machines, traffic lights, and many automated systems.
🧩 Key Parts of a Finite State Machine
Let’s break it down into its main pieces:
- States – The different conditions or “modes” the circuit can be in.
(Like: idle, waiting, active, etc.) - Inputs – Signals that tell the machine what’s happening.
(Like pressing a button or a sensor changing.) - Outputs – The results or actions of the system based on the current state and input.
(Like turning on a light or sending a signal.) - Next State Logic – Rules that decide where to go next when inputs arrive.
- Memory (Flip-Flops) – These store the current state.
💡 Everyday Example — A Simple Turnstile Gate
Imagine a turnstile gate at a metro station — that metal barrier that unlocks when you insert a coin.
It has two states:
- Locked (initial state)
- Unlocked
Now, let’s describe its behavior:
| Current State | Input | Next State | Output |
|---|---|---|---|
| Locked | Coin inserted | Unlocked | Gate opens |
| Unlocked | Push bar | Locked | Gate closes |
Here, the input decides the next state, and the machine behaves accordingly.
That’s exactly how a finite state machine works — simple, predictable, and based on rules.
🧮 Types of Finite State Machines
There are two main types of FSMs used in digital circuits:
1. Moore Machine
In a Moore machine, the output depends only on the current state.
Inputs don’t directly affect the output — they just determine the next state.
Think of a vending machine light that says “Ready” or “Dispensing” —
the light changes after the state changes.
Output = f(State)
2. Mealy Machine
In a Mealy machine, the output depends on both the current state and the input.
This means the system can react faster because outputs can change as soon as inputs change.
Output = f(State, Input)
So, Mealy machines are like systems that immediately respond to what’s happening outside,
while Moore machines respond after changing their state.
🧭 How FSM Works (Step-by-Step)
Let’s take a simple 2-bit counter as an example of a state machine.
| Present State | Input | Next State | Output |
|---|---|---|---|
| 00 | 1 | 01 | 0 |
| 01 | 1 | 10 | 0 |
| 10 | 1 | 11 | 0 |
| 11 | 1 | 00 | 1 |
In each clock pulse:
- The circuit reads its current state (what’s stored in flip-flops).
- It checks the input (like a clock tick).
- Then it moves to the next state (by updating the flip-flops).
- And it produces an output based on the FSM type (Moore or Mealy).
This cycle keeps repeating — input → state → output → next state.
🖼️ Simple Diagram of a Finite State Machine
Here’s a simple text version of what a basic FSM looks like:
┌────────────┐
Input → │ Next-State │ → Next State
│ Logic │
└─────┬──────┘
│
▼
┌────────────┐
│ Flip-Flop │ (stores current state)
└─────┬──────┘
│
▼
┌────────────┐
│ Output │ ← depends on State or (State + Input)
└────────────┘
Everything is connected by the clock, which makes sure the state changes happen in sync.
🌀 Graphical View — State Diagram
Let’s draw a state diagram for our simple 2-state turnstile example:
+-----------+
| Locked |
+-----------+
| (Coin)
▼
+-----------+
| Unlocked |
+-----------+
| (Push)
▼
(Back to Locked)
Each circle represents a state.
Each arrow represents a transition (triggered by an input).
It’s a clear, visual way to see how your system moves.
⚡ Where FSMs Are Used
Finite state machines are everywhere in digital electronics.
Here are a few common examples:
- Traffic light controllers
- Vending machines
- Elevator control systems
- Sequence detectors
- Digital watches
- Microprocessor control units
Basically, anytime a device needs to respond to events in a specific order, it uses an FSM.
🧭 Key Differences Between Moore and Mealy Machines
| Feature | Moore Machine | Mealy Machine |
|---|---|---|
| Output depends on | Only state | State + input |
| Reaction speed | Slower | Faster |
| Design | Simpler | Slightly complex |
| Stability | More stable | Can be more responsive |
Both have their own advantages — engineers choose based on speed, simplicity, and application.