# Is anyone here interested in Train Signals and how they work?

**URL:** https://discourse.nodered.org/t/is-anyone-here-interested-in-train-signals-and-how-they-work/19759
**Category:** General
**Created:** [31 December 2019 01:46 UTC](https://discourse.nodered.org/t/is-anyone-here-interested-in-train-signals-and-how-they-work/19759 "2019-12-31T01:46:51Z")
**Posts on this page:** 1
**Showing post:** 13

<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: [1 January 2020 11:04 UTC](https://discourse.nodered.org/t/is-anyone-here-interested-in-train-signals-and-how-they-work/19759/13 "2020-01-01T11:04:51Z")

</div>

Couple of suggestions.

What you're trying to do is implement a 'control system' using a Node-RED flow.  
So the first thing to do is work out a specification or algorithm that defines what should happen under certain conditions. You probably have this already on your piece of paper. Having a good 'spec' also means you can create a testbench to prove the system works under all conditions.

For a very basic control system it normally means... "when I have these inputs then create this output".  
Just like having a logic gate to detect an input and produce an output.

In your situation you are dealing with a non-trivial control system that has 'states' as well as 'inputs', so the complexity increases. For example detecting if there is a train within a block, about to leave a block or whether the block is empty will affect the track-side signals.

Many real-life (control) situations like getting money out of a cash machine are really a simple state machine. You have to do things in a certain sequence in order to get to the final result and sometimes there may be more than one path to get to a certain point.

I'm a big fan of finite state machines (FSMs) as it's usually a fairly easy task to construct a (graphical) state diagram to show how you can navigate from one state to another. Once the state diagram is complete and providing there are no dead-ends or unreachable states - you can code it.  
Which language you use to do this is up to you, but since we are talking about Node-RED then JavaScript is probably the best choice.

If you want to see a simple example of a FSM then have a look at the Mathematical Magic Machine, I published on Discourse over Christmas. Hope you find this useful.

[Mathematical Magic Machine](https://discourse.nodered.org/t/matts-mathematical-magic-machine-m4/19775)

---

_[View the full topic](https://discourse.nodered.org/t/is-anyone-here-interested-in-train-signals-and-how-they-work/19759)._
