How to add infrared and Hall-effect sensors to DCC-EX
Wire cheap infrared or Hall-effect sensors to a DCC-EX command station, define them for JMRI or EXRAIL and use them to trigger automation.
- Time
- 1–2 hours
- Difficulty
- Medium
- Cost
- Low cost
- Steps
- 6
- Checked
What you’ll need
- Infrared obstacle/beam-break sensor modules or Hall-effect sensors Search Amazon for IR obstacle sensor module
- Small magnets for Hall sensors Search Amazon for small neodymium magnets
- Jumper wires Search Amazon for jumper wires male female
- A DCC-EX command station
- Optional: MCP23017 I/O expander Search Amazon for MCP23017 I2C expander
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
- Check the sensor module's supply voltage suits your board before connecting it.
Step by step
-
Step 1: Choose a sensor type
DCC-EX's comparison: IR sensors are cheap and need no changes to stock, but room lighting affects them; reflective types hide easily in the trackbed, beam-break types are more reliable but harder to hide. Hall-effect sensors are cheap and ignore light, but need a magnet under the stock and only detect the magnet's position; they can be unreliable at speed.
Next: step 2 -
Step 2: Mount the sensor
Reflective IR: in a hole between the sleepers. Beam-break: emitter one side, receiver the other – DCC-EX notes placing them square to the track can trigger on every wheelset, while angling them (about 45°) helps detect the train as a whole.
Next: step 3 -
Step 3: Wire it
Connect the sensor's VCC and GND to the command station's supply pins and its output to a free digital I/O pin, or to a pin on an I/O expander such as an MCP23017 (DCC-EX).
Next: step 4 -
Step 4: Define the sensor for JMRI
Send
Next: step 5<S id vpin pullup>– for an active-low sensor on pin 22:<S 22 22 1>. When triggered DCC-EX reports<Q 22>, and<q 22>when clear. Use0for active-high sensors. -
Step 5: Or use it directly in EXRAIL
EXRAIL refers to the pin (vpin) directly:
Next: step 6AT(22)waits until the sensor is triggered,AFTER(22)waits until it clears. Put a minus sign in front for active-high sensors, e.g.AT(-22). -
Step 6: Test it
Wave a hand or a wagon over the sensor and watch the JMRI sensor table or the serial log.
Tips
- Shield IR sensors from sunlight and spotlights.
- Fit magnets at the same place on every loco so stopping positions are consistent.
Questions people ask
IR or current detection?
Current detection covers a whole section and suits signalling; IR and Hall sensors detect a point, which suits stopping a train at a platform.
Can I make sensors permanent at start-up?
Yes – DCC-EX explains how to store sensor definitions in its startup configuration.
Sources
Checked 18 October 2026. We wrote this guide in our own words, using:
- DCC-EX: which sensor type to use (dcc-ex.com)
- DCC-EX: infrared sensors (dcc-ex.com)
- DCC-EX: EXRAIL command reference (dcc-ex.com)
Was this guide helpful?
Report a problem with this guide
Printed from dcctrainautomation.uk/guides/add-ir-and-hall-sensors-to-dcc-ex/ · 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.