# 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:** 1\
**Showing post:** 3

<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).

---

_[View the full topic](https://discourse.nodered.org/t/integration-of-a-state-machine/13740)._
