Automated Train Reverse Loop Using Arduino

5,028

15

13

Making reverse loops can help in model train layouts to change the direction of trains, which cannot be done with turntables. In this way, you can create single-track layouts with a reverse loop on each end to run trains without any pause or interruption. So, without further ado, let's get started!

Step 1: Gather All the Required Stuff!

For this project, here is the list of required parts and components:

  • An Arduino microcontroller board, recommended ones are UNO, Leonardo, MEGA.
  • An Adafruit motor driver shield.
  • A 12-volt DC power source(can be a battery or an adapter with a current output capacity of at least 1.5 amp)
  • Six male to male jumper wires:
  1. A pair to connect the turnout to the motor driver.
  2. Second pair to connect the power of the outer track to the motor driver.
  3. Third pair to connect the inner loop to the motor driver.

  • A 'sensored' track.
  • 3 female to female jumper wires(to connect the sensor to the Arduino board).

Step 2: Program the Arduino Board

If you don't have Arduino IDE on your computer, download it from here. The library for the Adafruit motor driver shield can be found here, in case you don't have it in your IDE. Make sure you install this in your IDE before compiling the program. If you need help installing a library, check this link out.

Step 3: Isolate the Inner Loop Tracks

Using 4 insulated rail joiners, isolate the inner loop of track from the outer track. Click on the image for more info.

Step 4: Make the Layout

I used N-gauge Kato Unitrack to make this layout. You can use any other track as long as everything works properly.

Step 5: Plug the Shield on the Arduino Board and Make the Wiring Connections

Before attaching the motor driver shield, make sure all of the pins are aligned and then push the shield down to attach it firmly to the Arduino board. When keeping the board in an upright position(see the above image) such that the analog input pins are on your side, make the following connections:

  • Connect the turnout wires to the terminal block marked 'M4' by connecting the +ve or the red wire to the upper terminal and the -ve or the black wire to the lower terminal.
  • Connect the power wires of the inner section of the loop to the terminal block marked 'M2'. Connect it anyway for now and change the polarity later if the train or the locomotive moves in the wrong direction inside the loop or just stops.
  • Connect the outer track's power to the terminal block marked 'M1'. Do the same later as you will do for the track power in the inner loop.

Step 6: Connect the 'sensored' Track to the Arduino Board

Connect the pins of the sensor as follows:

  • VCC to +5-volts pin of the Arduino board.
  • GND to GND pin of the Arduino board.
  • OUT to A0 pin of the Arduino board.

Step 7: Place the Locomotive on the Track

Place the locomotive on the outer section of the track to test the setup.

Step 8: Power Up the System

Power up the Arduino board and the motor driver by connecting either the VIN and GND pin respectively to 12-volt power and ground respectively or by connecting the barrel connector of the adapter to the power socket of the Arduino board. Double-check all of the wiring connections and turn on the power.

Step 9: Watch It Working!

If everything goes on well, then your setup should work like the one shown in the above video.

Step 10: What's Next?

Now that you have got the example setup running, you can further add another reverse loop on the other end of the outer track to make the train go running in both the directions on a single track without any interruption(you will need to modify the Arduino program for that). Show off your skills by modifying the Arduino program to increase the functionality of this project or just simply let me know what you did with this. Let me know if you made this project to help me know if this was useful to you at all.

I wish you happy railroading. All the best!

Share

    Recommendations

    • 1 Hour Challenge

      1 Hour Challenge
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest
    • Pets Challenge

      Pets Challenge

    13 Discussions

    0
    None
    KushagraK7AJS60

    Reply 4 months ago

    The turnouts I had used here have solenoids inside them which allow them to controlled by a microcontroller through an H-bridge circuit. They are manufacured by Kato.

    1
    None
    JohnW51

    5 months ago on Step 10

    Hmm. I think you could accomplish the same thing with a dual-core latching relay. Much simpler and cheaper.

    5 replies
    1
    None
    KushagraK7JohnW51

    Reply 5 months ago

    Agreed, a relay can be used but an Arduino microcontroller board can prove to be helpful for adding more functions to the layout in the future.

    1
    None
    JohnW51KushagraK7

    Reply 5 months ago

    Yes, of course. No doubt about that. I have a bro-in-law that is into trains. Started a layout about 12 years ago. Never finished it. Now he says he's going to tear it all down and start over. Sure he is. ;-) I offered to automate parts of it for him using an Arduino. Your track sensor is a great place to start. :-)
    I'm a retired EE. We used many reflective sensors on equipment I worked on, but I see now the ones with leads are no longer available--only surface mount. I guess that could work, but kinda touchy to solder and my hands aren't as steady as they used to be. It would be cool if someone would offer a complete circuit board with all surface mount components. It would probably fit under the track and be invisible.

    0
    None
    JohnW51KushagraK7

    Reply 5 months ago

    Yes, I've seen that Instructable, but it doesn't mention anything about the circuit board that I could find. It's not in the materials list. Also the other components are not in the materials list.

    0
    None
    KushagraK7JohnW51

    Reply 5 months ago

    I bought those sensors from here.
    You can find such sensors with through-hole IR LED and the photodiode on Amazon. You will need to do the following:
    1. Mark the +ve and -ve connections on the circuit board for the IR LED and the photodiode if they are not present.
    2. Unsolder the IR LED and the photodiode and follow the instructions in the image below:

    IR sensor help.png
    0
    None
    KushagraK7jonathanwheat

    Reply 5 months ago

    This project is for DC locomotives. Since I just started working with model trains this year, I chose DC to start with. I will see to making a reverse loop for DCC in the future.

    1
    None
    jonathanwheatKushagraK7

    Reply 5 months ago

    That's awesome, welcome to the hobby! Thanks for letting me know, its a cool project. Use whatever you want, DC, or DCC - depends on what you want to accomplish. Since you're into Arduino - you may want to look into the DCC++ project - essentially building a DCC control station with Arduino. A friend of mine built it and its pretty easy to build and use, you can hook it in to JMRI to program and control your locos. I haven't seen an auto-reverse circuit for it yet tho :)

    1
    None
    raphan

    6 months ago

    Here the Arduino is a bit overwhelming, a simple relay can make the job. But an Arduino permits a lot of functions that add original features to a setup.

    1 reply
    0
    None
    KushagraK7raphan

    Reply 6 months ago

    Thanks for your feedback! The main purpose of using an Arduino microcontroller was to automate the layout to let all the stuff happen without any human interference. This can prove to be very useful when a layout needs to be put up at a display where you cannot be always present to keep a control on trains and turnout switches, also, fully automated model train layouts look quite impressive.