DCC Auto-Reverser

We were recently asked to build a module that could automatically reverse a locomotive between two end points for use on a small point-to-point switching layout. The idea was to provide a means for continuous running of a train while working on the layout or to break in new locomotives without user intervention.  The end result is described here, with instructions for building your own.  At the current time, this is a mostly a DIY project, but if you want help building one, please let us know.

The Reverser

Here is video of the reverser in action.  You can program up to 16 locomotive addresses using the LCD panel and buttons.  This lets you control one of your locomotives without having to remove the others from the layout.  You can also set the speed and the ramp down / ramp up times while reversing direction.


The reverser is built from the following parts:

The Arduino Mega is required, not for memory, speed, or IOs, but because it’s the only Arduino with timer compare outputs on the correct pins.

Motor Shield Modifications

The motor shield must be modified by cutting both Brake Disable jumpers and the Channel A current sense (SNS0) jumper.  This is to free up those pins for use by the LCD Shield.

Modification of the Arduino Motor Shield (CC BY-SA)
IR Sensor Connections

The IR sensors connect to several of the Arduino header pins.  Some versions of the LCD Shield provide separate holes where wires can be soldered.  If not available, the wires can be soldered directly to the pins on top of the LCD shield.

IR Sensor Connections

Power for the IR sensors comes from the 5V (red) and GND (green) pins.  The white output wires from the IR sensors connect to the A4 and A5 inputs.  The order of the sensors on the A4/A5 pins doesn’t matter as the module will automatically determine the direction.


Two pieces of software are needed to build the auto-reverser.  First, CmdrArduinoMS is the DCC command station library used to build the DCC packets and output the DCC waveforms using the motor shield.  This must be installed as a library in the Arduino environment.  See the general instructions for Arduino library installation.

The second piece of software is the reverser code itself.  This can also be found on GitHub.  See the src/dcc-reverser/dcc-reverser.ino sketch.  After installing the CmdrArduinoMS library, upload the dcc-reverser.ino sketch to the Arduino Mega board.

Final Connections

The track connects to the motor shield on the B outputs.

Connecting to the Arduino Motor Shield (CC BY-SA)

Provide 12V DC power, either through the VIN screw terminals on the motor shield, or via the barrel jack on the Arduino Mega board.  The design has a 1A software current limit, so make sure the power supply can provide at least that much current to maximize the drive capability of the auto reverser.  Connecting power to the screw terminals on the motor shield may provide the best performance at higher output currents.


The buttons on the LCD Shield perform several actions:

  • LEFT/RIGHT scroll through the list of pre-programmed locomotive addresses
  • UP/DOWN control the throttle setting
  • SELECT toggles through the ramp up/down settings

Up to 16 locomotive addresses can be programmed into the module.  To configure, press and hold SELECT for 5 seconds to enter configuration mode.  In this mode, LEFT/RIGHT scrolls through the 16 decoder address slots. The UP/DOWN buttons set the address associated with the selected address slot. You can press and hold the button to auto-increment. When done setting all the addresses you need, press SELECT to store them to non-volatile memory, so they will be available at all subsequent power-ups.

Always start with the locomotive between the two IR sensors. If outside of them, or covering one when started, the module will get very confused… On power up, it learns the order of the sensors relative to the locomotive forward/reverse direction by starting in the forward direction.  The first sensor covered is then the one in the “forward” direction and the module continually ping-pongs from there. If you swap out locomotives or turn the locomotive, reset (or power cycle) the module so it will relearn the direction.

When reversing direction, the speed will ramp down, reverse, then ramp back up. The ramp value (configured by the SELECT button) controls the ramp rate. This value is the number of milliseconds between steps while ramping up/down. For example, with a throttle setting of 40 and a ramp value of 50 (the default), it will take 40 * 50ms = 2 seconds to ramp down, then another 2 seconds to ramp back up.  This can provide additional momentum during operation.


The DCC Auto-Reverser is a relatively easy project that can add some fun to a layout while working on it, or for breaking in new locomotives, without needing any manual intervention.  It is built from readily available Arduino components and the reliable, easy to install CKT-IRSENSE proximity sensors.



  1. Hi. Should the regular DCC controller remain connected to the track or should track be isolated from remainder of tracks and does the Arduino provide provide power as well as DCC control signal?

  2. The Arduino provides both power and DCC signal, so it will need to be isolated from the main DCC system on the layout.

  3. I see the red (5v), black (GND) and white (A4,A5) wire connections , but where do the blue and yellow wires from the sensors attach?

Leave a Reply

Your email address will not be published. Required fields are marked *