How to Draw a State Machine Diagram in UML
This page provides a tutorial for drawing state diagrams in the Unified Modeling Language (UML). Outlined below are the basic steps for building these diagrams in Lucidchart—a free, user-friendly chart maker.
We also offer tutorials and examples for other types of UML diagrams, including component diagrams, class diagrams, deployment diagrams, use case diagrams, and object diagrams.Demo here Sign up free
How to create a State Machine Diagram
Before you begin drawing, you will likely find it valuable to brush up on some of the basics. First, take a look at our UML guide, and then, read through our State Machine Diagram tutorial. Once you have finished reviewing the fundamentals, you can start with everything you need to know fresh in your mind.
IDENTIFY USE CASES & ELEMENTS
To begin, identify what the purpose of your diagram is, and what elements you’ll be describing with it. To help you determine the purpose, these are the main applications of a state diagram:
- Portraying the movement of an object from state to state.
- Showing how event-driven objects work in reactive systems.
- Examining how use case sequences can be applied to a business scenario.
- Providing an overview of a complex state machine or series of state machines.
For your diagram, you may choose to use one or several of these use cases.
The main elements of a state diagram are states and transitions. Try making a list of each state that should be included in your diagram. One good way to think about it is to consider which state the user will be experiencing as the process continues. Then think about what transitions and events are necessary to get them to experience that state. For example, in this snippet of a calendar state diagram below, an appointment must be added to the calendar before the “Appointment added” state can be realized.
ADD UML SYMBOLS
Open the Lucidchart editor and turn on the shape library for UML. Scroll down for the state and activity sub-library and drag out a black circle to start the diagram. This circle indicates the initial state.
Click on any point on your initial state circle to drag out a transition arrow, a shape which leads to a change in states and points in the direction of the process flow. When you are finished dragging out your arrow, the editor will automatically prompt you to choose a new shape to connect with your arrow. Choose the state shape, a rectangle with rounded corners.
Next, simply click and type to label your state. To create a message on your transition arrow, double-click the line where you want to add text. For events and triggers, you can also drag out a text box directly above your transition arrow.
If you need to express multiple options for your transitions, choose the diamond shape, which indicates a pseduostate. You can draw out multiple transition arrows from this shape.
When your state diagram (or in more complex diagrams, one of your state machines) is finished, choose the bordered circle to indicate the final state. In the example of a calendar system below, you can see that the state machine that ends in a final state is enclosed in a box within the diagram.
Lucidchart lets you customize every detail of your diagram for a professional, cohesive look. Once you've outlined the basics, it's easy to change the color, size, and direction of lines and shapes.
Be sure to carefully proofread your diagram once you have finished drawing. Make sure all the transitions are accurate and move from state to state in a logical flow. You may also want to have someone familiar with UML look over your diagram to ensure that it's correct and readable.
Lucidchart's features are constantly evolving to keep pace with industry standards. To see which UML shapes are currently offered, sign up for free and explore the product.
As you can see, Lucidchart makes it effortless to produce quality UML diagrams. You can share these diagrams with anyone, or work on them together in real-time!