I am working for almost 2 months now on an open automation software called "The Lego Train Project".
I thought I would make a separate and clean post to show a very concrete example with full source code. First let's see how it looks like in action: The software used in this demo can be downloaded for free here: https://www.dropbox.com/sh/zl0tqfmthhp48tt/AADeVc1lU5znYSvnlAN8HL-1a?dl=1 Here is how it is setup: I have 4 hubs used in this example:  - Red Train Hub with a train motor and a color detector.
 - Yellow Train Hub with a train motor and color detector.
 - Switch 1 Hub with a simple motor
 - Switch 2 Hub with a simple motor and a distance detector. (Note that the dashboard has 2 more hubs but they are not used in this example). Let's dive now into Sequence #1.
When you click Start there, it activates the following code: // Desactivate detectors to let the train leave Hub[0].State[0] = 1; // "Switch 2" is routing to large route Hub[2].ActivateSwitchToRight("A"); // Wait for Switch to Activate in Full - Double Cross Switch is pretty slow to switch Wait(1000); // Start "Red Train" Hub[4].SetMotorSpeed("A", 60); // Let the train go through Wait(3000); // "Switch 2" is routing to small route Hub[2].ActivateSwitchToLeft("A"); // Wait for Switch to Activate in Full Wait(1000); // Start "Yellow Train" Hub[1].SetMotorSpeed("A", 60); // Let the train go through Wait(3000); // Prepare "Switch 1" to welcome "Red Train" Hub[0].ActivateSwitchToRight("A"); // Slow Down Yellow Train Hub[4].SetMotorSpeed("A", 50); // Re-activate Events for both trains Hub[0].State[0] = 0; Then we need 2 separate Sensor Events to be able to stop trains. First Event triggers when Yellow Train drive above 'White'. It then execute the following code: // We make sure the trains left. We don't want to stop them too early! if (Hub[0].State[0] == 0) { // Stop Yellow Train Hub[1].Stop("A"); // Switch Prepare Train on the Left Hub[0].ActivateSwitchToLeft("A"); } This codes waits for the initial sequence to be done and if it triggers, stops the Yellow Train and activate the first switch to prepare to welcome the Red Train. Second Event triggers when the Detector of Switch 2 has a train passing in front of it. It then execute the following code: if (Hub[0].State[0] == 0) { // Stop Red Train Hub[4].Stop("A"); } I hope you find this useful!