Skip to content

The light switch example

The most basic example of a state machine that actually does something is a light switch. In this scenario there is a light bulb and a switch to turn the bulb on and off. Of course there’s also a power source and some electrical cabling to put it all together, but for the purpose of our model we can omit them.

The behavior of a light switch

When modeling the light switch example as a statechart, we can disregard everything (even the bulb) except for the switch. The behavior of the switch is very simple:

  • Initially the light switch is off, i.e., it is in its Off state.
  • If the light switch is operated while being in its Off state, it changes to its On state.
  • If the light switch is operated while being in its On state, it changes to its Off state.