Step 4: Make the Layout

The layout will contain a passing siding with a magnetic uncoupler track at the exit of the siding to let the locomotive uncouple from the rolling stock before leaving the siding. A ‘sensored’ track will be installed just after the siding to let the microcontroller know when the locomotive leaves the siding or crosses that particular section of the track.

Another ‘sensored’ track will be installed before the siding such that the length of track between this ‘sensored’ track and the siding with respect to the train’s direction of movement is greater than the length of the train.

After setting up the layout, make sure the track rails are clean to ensure the smooth running of the train.

Step 5: Connect the Turnouts to the Motor Driver

Connect both the turnouts in parallel(+ve and -ve of one to the +ve and -ve of the other respectively). Connect the parallel wired turnouts to the output pins of the motor driver module marked ‘OUT1’ and ‘OUT2’. You might need to reverse the turnout connection to the motor driver’s output if they switch to the wrong direction after powering up the setup.

Step 6: Connect the Motor Driver to the Track Power Feeder

Connect the track power feeder’s wires to the output pins of the motor driver marked ‘OUT3’ and ‘OUT4’. You might need to reverse the polarity of the wiring connection if the locomotive starts to move in the wrong direction after powering up the setup.

Step 7: Connect the Motor Driver to the Arduino Board

Remove the jumper connector from the pin of the motor driver marked ‘ENB’. Connect the ‘+12-V’ terminal of the motor driver module to the ‘VIN’ pin of the Arduino board. Connect the ‘GND’ pin of the motor driver module to the ‘GND’ pin of the Arduino board. Make the following connections between the motor driver and the Arduino board:

Motor driver -> Arduino board

IN1 -> D12

IN2 -> D11

IN3 -> D9

IN4 -> D8

ENB -> D10

Step 8: Connect the ‘sensored’ Tracks to the Arduino Board

Connect the ‘VCC’ pins of the sensors to the ‘+5-volt’ pin of the Arduino board. Connect the ‘GND’ pins of the sensors to the ‘GND’ pin of the Arduino board.

Connect the ‘OUT’ pin of the sensor at the exit of the siding to the pin ‘A1’ of the Arduino board. Connect the ‘OUT’ pin of the remaining sensor to the pin ‘A0’ of the Arduino board.

Step 9: Connect the Arduino Board to Power

Connect the Arduino board to a 12-volt DC power source through the power jack.

Step 10: Place the Rolling Stock and the Locomotive on the Tracks

Using a rerailing tool, position the locomotive on the mainline and the rolling stock in the siding.

Step 11: Check All the Wiring Connections and the Trains

Make sure the locomotive and the rolling stock are not derailed. Double-check all of the wiring connections and take care of the polarity of the power connections.

Step 12: Turn on the Power and Get the Train Running

If everything went well, you should see your locomotive starting to move and run as in the video. If the locomotive starts to move in the wrong direction or the turnouts switch in the wrong direction, reverse the polarity of their wiring connection with the output terminal of the motor driver module.

Step 13: Modify the Project

Go ahead and tinker with the Arduino code and the design to add more functions, run more trains, add more turnouts and so on. Whatever you do, all the best!