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
What you’ll need
- A DCC-EX command station (see our build guide)
- An end-to-end line with a station at each end and overrun beyond each stopping point
- Two IR or Hall-effect sensors Search Amazon for IR obstacle sensor module
- Jumper wire Search Amazon for jumper wires male female
- A computer with EX-Installer
- A reliable, speed-set loco
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
-
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 -
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 -
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 -
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:
Next: step 5FWD/REVset direction and DCC speed,AT(pin)waits for a sensor,STOPsets speed to 0,DELAYis in milliseconds andFOLLOWjumps to a sequence. For active-high sensors put a minus sign before the pin, e.g.AT(-22). -
Step 5: Upload it
Run EX-Installer again and include your
Next: step 6myAutomation.hwhen it compiles and loads the software. -
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,
Next: step 7SENDLOCO(loco, route)starts a route with a specific loco – for exampleSENDLOCO(3, 1)in your start-up section. -
Step 7: Tune it
Adjust the speed in
FWD/REV, the platformDELAYand 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;
ESTOPin 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:
- DCC-EX: EXRAIL command reference (dcc-ex.com)
- DCC-EX: infrared sensors (dcc-ex.com)
- DCC-EX: which sensor type to use (dcc-ex.com)
- DCC-EX: install the software with EX-Installer (dcc-ex.com)
- NMRA S-9.2.2 Configuration Variables (July 2012) (nmra.org)
Was this guide helpful?
Report a problem with this guide
Printed from dcctrainautomation.uk/guides/automate-a-station-shuttle/ · Checked 18 October 2026 · General information only. Follow the maker’s instructions for your own equipment, and keep mains wiring inside properly made, enclosed power supplies.