DCC Train AutomationAn independent UK guide to automating a DCC model railway — home

Automation projects

How to automate a station shuttle with DCC-EX EXRAIL

Make a train run back and forth between two stations on its own, pausing at each platform, using two sensors and a short EXRAIL script on a DCC-EX command station.

Time
Half a day
Difficulty
Medium
Cost
Low cost
Steps
7
Checked
Report a problem
Automatic end-to-end shuttleA single line runs between two stations with a buffer stop at each end. A sensor near each end tells the controller (a computer running layout software, or an Arduino) that the train has arrived. The controller slows and stops the train, waits, then sends the command to reverse, through the DCC command station that powers the track.Station AStation BsensorsensorControllercomputer or ArduinoCommand stationpowers the trackSensor signals in, speed and direction commands out
Automatic end-to-end shuttle A single line runs between two stations with a buffer stop at each end. A sensor near each end tells the controller (a computer running layout software, or an Arduino) that the train has arrived. The controller slows and stops the train, waits, then sends the command to reverse, through the DCC command station that powers the track.

What you’ll need

As an Amazon Associate we earn from qualifying purchases. The Amazon links go to search results, so you can compare what’s available.

Before you start

  • Leave plenty of overrun and a buffer stop at each end in case a sensor fails.
  • Don't leave automated trains running unattended.

Step by step

  1. Step 1: Plan the stopping points

    Place a sensor before each buffer stop, leaving enough track beyond it for the train to slow and stop. Momentum (CV3/CV4) lengthens the stopping distance, so test it.

    Next: step 2
  2. Step 2: Fit and wire the sensors

    Wire the two sensors to free I/O pins, for example 22 (station B) and 23 (station A). See our sensor guide for IR versus Hall-effect choices.

    Next: step 3
  3. Step 3: Check the sensors work

    Using EX-WebThrottle or the serial monitor, trigger each sensor and confirm the command station sees it.

    Next: step 4
  4. Step 4: Write the EXRAIL script

    EXRAIL scripts live in a file called myAutomation.h, uploaded to the command station once. A simple shuttle:

    `` // myAutomation.h – end-to-end station shuttle // Sensor at station B on pin 22, sensor at station A on pin 23 AUTOMATION(1, "Station shuttle") FWD(40) // head for station B AT(22) // wait until the train reaches B STOP DELAY(15000) // 15 seconds at the platform REV(40) // head back to A AT(23) STOP DELAY(15000) FOLLOW(1) // repeat ``

    Commands come from the DCC-EX EXRAIL reference: FWD/REV set direction and DCC speed, AT(pin) waits for a sensor, STOP sets speed to 0, DELAY is in milliseconds and FOLLOW jumps to a sequence. For active-high sensors put a minus sign before the pin, e.g. AT(-22).

    Next: step 5
  5. Step 5: Upload it

    Run EX-Installer again and include your myAutomation.h when it compiles and loads the software.

    Next: step 6
  6. Step 6: Start the shuttle

    Automations are advertised to throttle apps, so you can start it on a chosen loco from a WiThrottle-compatible app. Alternatively, SENDLOCO(loco, route) starts a route with a specific loco – for example SENDLOCO(3, 1) in your start-up section.

    Next: step 7
  7. Step 7: Tune it

    Adjust the speed in FWD/REV, the platform DELAY and the loco's momentum until stops look natural.

Tips

  • DELAYRANDOM(min, max) gives a less predictable dwell time.
  • Keep a hand near the power button the first few runs; ESTOP in EXRAIL stops all locos.

Questions people ask

Can I do this with other software?

Yes – iTrain, Rocrail, JMRI and others can run shuttles using detection. EXRAIL runs inside the command station, so no computer is needed once uploaded.

Can it switch points too?

Yes – add THROW(id) and CLOSE(id) for defined turnouts.

Sources

Checked 18 October 2026. We wrote this guide in our own words, using:

  1. DCC-EX: EXRAIL command reference (dcc-ex.com)
  2. DCC-EX: infrared sensors (dcc-ex.com)
  3. DCC-EX: which sensor type to use (dcc-ex.com)
  4. DCC-EX: install the software with EX-Installer (dcc-ex.com)
  5. NMRA S-9.2.2 Configuration Variables (July 2012) (nmra.org)

Tags: automation DCC-EX end to end EXRAIL sensors shuttle

Was this guide helpful?

Report a problem with this guide
What’s the problem?

Please don’t include personal details we don’t need. See our privacy notice.