Modeling state machines – A look at UML and SysML

Daniel Saffer

16/08/2019

Finite-state machines, also known as state machines, or state diagrams, define the invariable states of a system. Documentation can be done in tabular or graphical format. Since the number of table rows increases significantly with the number of states, it is more concise to use the graphical approach. This article will demonstrate how state machines can be modeled.

Introduction

Fig. 1: Simple state machine

A state diagram always represents the states and their state transitions (see Figure 1). The graphical representation allows for immediate identification of deadlocks and isolated states. Deadlock occurs when a state can be entered but not exited. Isolated states cannot be reached at all. States are often represented by circles, and transitions by directed arrows. It is important to note that only one state can be active at a time. Furthermore, an initial state is always defined, which is assumed upon a reset.

State machines in UML / SysML

However, the state machines in UML and SysML are somewhat more complex than just described. Here, the semantics of the state machine are specified in such detail that the machines can be executed and used for automatic code generation. The concept of state machines in UML goes back to the computer scientist David Harel, who, among other things, combined the properties of the Mealy and Moore machines. Every system has states. Depending on the state, events trigger internal reactions and possibly state changes. Events can also be discarded if the state cannot interpret them. In UML and SysML, states are represented by rounded rectangles. The state name is inside the rectangle. UML also has three defined behaviors to further specialize a state. For example, the entry behavior (entry), the state behavior (do), and the exit behavior (exit) can be defined for each state. These behaviors are also stored within the rectangle. State transitions are also called transitions in modeling languages. A transition is a directed arrow between two states and defines the trigger, the condition for the transition, and a possible behavior. The notation is as follows:

Notation:
TriggerA, TriggerB, ... [Condition] / Behavior
Example:
User[presses power button] / shut down()

The UML further recognizes five types of events that can lead to a transition. These include the call event, the change event, the signal event, the time event, and the any receive event. The time event can, in turn, be divided into relative and absolute time events.

The following table shows the elements mentioned above graphically and briefly describes them.
Images can be clicked to enlarge.

symbol name Meaning
Condition The states of the state machine are represented as rounded rectangles. The state name is written inside.
state machine States can be divided into smaller states. At a higher, more general level, this symbol can be used to describe the divided states.
Transition A transition is a directed arrow between two states. The state changes in the direction of the arrow. Additionally, the trigger, condition, and behavior can be added (see above).
Call event An operation is called.
Change event A value changes in the value. If the Boolean expression is true, the next state is called.
Signal event A signal is received.
Relative time event The state is changed after a defined time.
Absolute time event The state is changed at a defined time.
Initial state The initial state, or start state, indicates where the state machine begins after a reset or power-on. It always points to the initial state using a transition.
Final state The final state indicates where the state machine ends. After that, execution is complete. One possible case would be, for example, shutting down a device.
Decision A decision always has one incoming and several outgoing transitions. A decision is made based on values.
history Historizing allows states to be saved. For example, if a device is turned on again, the state of the last operation is remembered and recalled. An example is a washing machine with a program selection via a dial. Each program represents a state. The washing machine jumps to the state selected via the dial.
Split and synchronize This symbol enables parallelization. Splitting allows multiple state machines to execute in parallel, which can then be merged again using synchronization.
Entry point Using the entry point, further entries into the state machine can be described.
Starting point The starting point can be used to describe further outputs of the state machine. An exit point terminates execution.
Scheduling Termination also ends the state machine. However, there is no final state.

Example

If you don't want to use automatic code generation or state machine execution in specific programs, it's generally recommended to keep the state machine as simple as possible. The following is an example of a state machine for a fan:

Fig. 2: State machine of a very simple fan

Figure 2 shows the state machine of a very simple fan. It knows the states "off" and "on." The fan is turned on via a button. It either turns off automatically after two hours to save energy or can be turned off by the user. The fan remembers the user's selected intensity via a dial. It can choose between three intensity levels. The fan never leaves the state machine.

More diagrams


Written by Daniel Saffer

Daniel Saffer is Chief Technical Officer (CTO) of MEDtech Ingenieur GmbH. In this role, he is responsible for the company's technical strategy and supports customer projects in medical technology. His focus is on the further development of safety-critical software solutions, regulatory requirements, and innovative technologies for the industry.


More articles

  • 09/09/2025
  • General, Software

In previous blog posts, I have introduced two essential components of a simple and universally applicable software architecture: events with dispatchers, listeners, and data pools. These already allow for many simple use cases ...

Read more
  • 19/03/2025
  • General, Companies, Events

We are pleased to invite you to an exclusive VDI event of Network Systems Engineering, which will take place in our office!On Friday, March 28, 2025, everything will be about the ...

Read more
  • 12/11/2024
  • General, Software, Testing, Tools

In safety-critical software projects, software quality is paramount. Especially for Class C software, which must be certified according to strict standards such as IEC 62304 (medical technology), it is essential that ...

Read more
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Strictly Necessary Cookies

Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.