# Integration of a State Machine

**URL:** https://discourse.nodered.org/t/integration-of-a-state-machine/13740
**Category:** General
**Created:** [27 July 2019 06:11 UTC](https://discourse.nodered.org/t/integration-of-a-state-machine/13740 "2019-07-27T06:11:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rayy](https://avatars.discourse-cdn.com/v4/letter/r/f08c70/32.png) [@rayy](https://discourse.nodered.org/u/rayy)
#### Post date: [27 July 2019 06:11 UTC](https://discourse.nodered.org/t/integration-of-a-state-machine/13740/1 "2019-07-27T06:11:21Z")

</div>

How do you integrate a final state machine into Node Red?

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [27 July 2019 06:16 UTC](https://discourse.nodered.org/t/integration-of-a-state-machine/13740/2 "2019-07-27T06:16:31Z")

</div>

Morning Rayyan,  
By simply using the search bar offered by the Node-RED forum...  
Then you will see a series of example, like [this](https://discourse.nodered.org/t/security-system/711). I haven't used it myself ...  
Bart

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [27 July 2019 06:28 UTC](https://discourse.nodered.org/t/integration-of-a-state-machine/13740/3 "2019-07-27T06:28:46Z")

</div>

You can also code a Finite State Machine (FSM) in JavaScript (if you understand the language).

Here's a link to a tutorial I wrote for my IoT students to code a FSM for UK traffic lights.  
There's a link to a NR flow as well.

> [@Finite State Machine (FSM) - UK traffic lights](https://discourse.nodered.org/t/finite-state-machine-fsm-uk-traffic-lights/1580):
>
> [UK traffic lights and FSM](http://resources-area.co.uk/node-red-flows/traffic_lights_and_fsm.pdf) The above link will take you to a tutorial about Finite State Machines (FSM). The model is based on the UK traffic light sequence. Here's a link to the Node-RED flow. [Node-RED flow](http://resources-area.co.uk/node-red-flows/fsm_traffic_lights.txt) Trust you enjoy reading the tutorial.

Note: If you look at the NR flow you will see the classic way of coding a FSM using 'case' statements.  
This traffic light example just moves from one state to another every 3-secs (so you can just use a simple counter in this very basic example).
