Introduction: Automated Model Railway Layout Running Two Trains
I made an Automated Model Train Layout with Passing Siding a while back. Upon request from a fellow member, I made this Instructable. This is somewhat similar to the project mentioned earlier. The layout accommodates two trains and runs them alternatively. So, without further ado, let's get started!
Step 1: Get All the Necessary Stuff!
For this project, here is the parts list:
- An Arduino microcontroller board(UNO, MEGA, Leonardo, and similar ones are recommended).
- An L298N dual H-bridge motor driver board.
- 4 male to female jumper wires(to connect the digital outputs of the Arduino board to the inputs of the motor driver board).
- 4 male to male jumper wires to connect the turnouts to the motor driver board.
- 2 male to male jumper wires to connect track power to the motor driver.
- A 'sensored' track.
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.
Make sure you go through the Arduino program before uploading it on your Arduino board. Since a large part of the operation is based on timing(that is why we managed it with a single sensor!). You may need to change some values since the size of the layout can affect how may trips the train will make around the layout, where the trains will stop, and so on. You will get an idea of how it works and you may even modify it to do whatever you can.
Step 3: Set Up the Layout
Step 4: Study the Circuit Schematic
Make sure you go through all of the details before proceeding.
Step 5: Make the Wiring Connections
Make sure no wiring connections are loose.
Step 6: Place the Locomotives on the Tracks
Let's just use the locomotives for testing purposes. Make sure the tracks are cleaned properly before starting the test to prevent stalling of locomotives.
Step 7: Power Up the Setup
Connect the 12-volt DC adapter to the Arduino board's power input, plug in the adapter and turn the power on.
Step 8: It's Done!
Step 9: Have You Done?
If you have made this project and if you can, share yours below for others to see your work. Go ahead! All the best!

Participated in the
Big and Small Contest
12 Comments
2 years ago
I have made this layout however i am having trouble adjusting the timing heelp please on how to do this
2 years ago
Thank you KushagraK7 for sharing. I'm 68 years old and just starting out with a DC N scale train layout. I had all the track layout done using analog means. But not so long ago I bumped in to Arduino control for trains and it got me interested in trying it out. After browsing lots of ideas I found yours the best for me to try at a basic level, don't have any experience in Arduino, although I started a beginners level course, I haven't gone pass blinking a led (ha, ha, ha), hope to learn more. It worked out very well. Now I will pick one of your other projects and see how it turns out and how I can apply it to my layout. Thanks for the inspiration.
Greetings from Puerto Rico,
Joe
Reply 2 years ago
Love to know that my projects inspired you to tinker with Arduino microcontrollers and model trains. This motivates me to make new projects.
By the way, this project can be a good start:
https://www.instructables.com/Simple-Automated-Mod...
Question 4 years ago on Introduction
why do you show two leads going to the turnouts - shouldn't there be three? I must be missing something.
Reply 4 years ago
The turnouts used in the project are based on a bipolar solenoid mechanism, the direction of the turnout switch can be controlled by momentarily altering the polarity of the current supplied to the turnout's solenoid. The switching direction depends on the polarity of electric current supplied to the turnout.
I hope it clears your doubt.
Question 4 years ago on Step 4
How track change gear works, is it controlled by Arduino or motor shield, as I am new to arduino? Please advise.
Reply 4 years ago
The track turnout change gears used in this project are Kato Unitrack #6 right and left-hand turnouts. These have a solenoid inside them which switches the track by changing the polarity of electric current going to the turnout wires, the current is supplied to the solenoid for a short period of time to switch the track. The motor shield uses an H-bridge motor driver to control the turnouts by controlling the polarity of the electric current flowing to the turnout solenoid.
I hope it helped. :)
Reply 4 years ago
Hi Kushagra, hope you are doing well. thanks for your comment above. however i dont have automated turnouts, i am using servo instead. please advise how to code servo turnouts.
thanks in advance.
Reply 4 years ago
I'll make the Arduino code for servo-driven turnouts and send them to you if you can provide me with your email address.
Reply 4 years ago
7021661919yd@gmail.com thanks
Question 4 years ago
hi..
can i change An L298N dual H-bridge motor driver board with An Adafruit motor driver shield? how to make that?
Regards
Reply 4 years ago
Just upload the attached program to the Arduino microcontroller and plug on the Adafruit motor driver shield. The connections are simple, M1 connects to the power feeder track and M3 connects to the turnouts of the siding wired together in parallel.