Introduction: Model Railway Layout With Automated Siding
Making model train layouts is a great hobby, automating it will make it a lot better! Let us take a look at some of the advantages of its automation:
- Low-cost operation: The whole layout is controlled by an Arduino microcontroller, using an L298N motor driver, their cost is almost nothing as compared to traditional train control throttles and power packs.
- Ideal to put up at a display: Since no human interference is required to keep a control on the layout, you can use it at a display where you cannot be always present to control the train and the turnouts.
- Great for microcontroller hobbyists: If you are or want to start with Arduino and programming, this is a great project for you to practice your skills.
If you are interested, you can also check the previous version of this project which is even simpler.
So, without further ado, let's get started!
Step 1: Watch My Project Working
Step 2: Get All the Material
To start, make sure you have all of the following:
- An Arduino microcontroller board, UNO is preferred.
- An L298N dual H-bridge motor driver board.
- 6 male to male jumper wires.
- 7 male to female jumper wires.
- A screwdriver.
- A 12 volt-DC power supply adapter.
- A track segment with IR proximity sensor attached on the underside(I used a Kato S62 track)
Step 3: Upload the Program to the Arduino Board
Download the Arduino IDE from here if you don't have it on your computer. Then download and open the given file.
Step 4: Lay the Tracks and Make the Layout
Make an oval loop with a passing siding somewhat as shown above. Make sure the distance between the sensor track and the first turnout the train will cross after crossing the sensor track is greater than the length of the train such that no part of the train is over the sensor track when it crosses the turnout.
Step 5: A Circuit Schematic Is Always Helpful
Click on the image to get a full view. Make sure you go through the full circuit schematic and all of the details before proceeding.
Step 6: Connect the Turnouts to the Output of the L298N Driver Board
Connect the red and the black wires of both the turnouts respectively to each other, resulting in a parallel connection. Then, connect the red wires to the out4 and the black wires to the out3 terminal of the motor driver board.
Step 7: Connect the Power Feeder Track to the Other Output of the L298N Driver Board
Connect the power feeder's white wire to the out1 and the blue wire to the out2 terminal of the motor driver board.
Step 8: Connect the L298N Driver Board to the Power Pins of the Arduino Board
Connect the 12-volt pin to the VIN pin of the Arduino board, the GND pin to the GND pin of the Arduino board, and preferably, the 5-volt pin of the motor driver to the 5-volt pin of the Arduino board.
Step 9: Connect the Sensor to the Arduino Board
Connect the VCC pin of the sensor to the 5-volt pin of the Arduino board, GND pin to GND pin of the Arduino board, and the OUT pin to the A0 pin of the Arduino board.
Step 10: Connect the Input Pins of the Motor Driver to the Arduino Board
Connect the digital pins of the Arduino board to the input pins of the motor driver board as follows:
- D9 to IN1
- D10 to IN2
- D11 to IN3
- D12 to IN4
Step 11: Place the Train on the Tracks
After checking all of the wiring connections, place the train on the siding.
Step 12: Power Up the Setup
Power up the setup and make sure the turnouts get switched to the siding, if not then just reverse the connections of the turnouts made with the motor driver. Also, make sure the train starts to move to forward direction. Reverse the feeder track's connection with the motor driver if the train moves in the wrong direction.
Step 13: It's DONE!
The project is complete, for now. You can tinker with the Arduino code to change the functionality of the layout, add more sidings, it's all customizable! I would love to know about any modifications you make to this project, let me know in the comments below. All the best!

Participated in the
Electronics Tips & Tricks Challenge
22 Comments
Question 1 year ago
I must congratulate you for the project as it describes in most easily understandable language. I am a retired person (Geologist) but trying my hands on my child hood hobby these days and I am trying to create a layout in my house. Could you please advice me as to how to introduce 'Switches or ON/OFF or Press Button (2 nos)' instead of IR sensors and code thereoff, as I want to decide when the train will run on main track or side track.
Thanks in advance.
Answer 1 year ago
I believe you want to control the turnouts' direction with the help of pushbuttons, right>
Reply 1 year ago
Yes my friend. Being a retired geologist I never had any idea about the electrical / electronic engineering, hence the request to kindly help me in pursuing my age old hobby. To start with I plan to add push buttons (I may be wrong with the usage of correct nomenclature) to decide on which platform the train should go. Also you may add drawing / sketch as to which connection goes where. Thanks in advance. Good day.
Reply 1 year ago
Sure. Please give me some time, I will share the circuit diagram soon.
Reply 1 year ago
This is in continuation with our discussions as regards Arduino, Turnout, relay and switch (ON / OFF). As mentioned I have a turnout similar to the picture attached. Could you please send me the sketch (Not Arduino program) as to how to connect the wires. Last time I did the same but unfortunate i have burned down the Arduino Uno board and relay. Regarding turnout I am not sure as I am not able to know the status. Hence the request. The link you have shared, is above me to understand, hence a simple electrical wiring diagram is requested herewith.
Thanks in advance.
Sushil Damle
5DEC2021@1647Hrs CA.
Reply 1 year ago
Thank you sir ji. Your name indicates you are from India, if so, can I ask you which city you are from. Sorry, if it's so.
Reply 1 year ago
You can get the circuit diagram from here:
https://odysee.com/@TechBuild:a/Push-button-Controlled-Model-Railroad-Turnouts:2?r=BfPRP8QNYHTeiN8UXAAVGDojhQYUz7yU&sunset=lbrytv
By the way, I am from Jabalpur.
Reply 1 year ago
Respected Mr Kushagra Ji,
Sorry for the delay in acknowledging your reply / email / informative link.
I am not able to recollect the 'Turnout' details such as model, manufactured by etc, that I am having in my house, but I am sure it has Three holes for the electrical connections. One could be (center) for power supply and other two sides could be for Left and Right side shifting of rail tracks. Presently I am away from my house and will be so for another couple of months and once I go back I will be able to send the photo graph of the same to you. I stay in a village about 110 kms from Pune (Maharashtra) by name Karanja.
If you are also in 'Railroad' hobby, could you please share few snaps of the layout made by you.
Thanks for the help.
With warm wishes.
Sushil Damle
23Nov2021@1212 Hrs CA.
Reply 1 year ago
If you have a 3-wire turnout, then this might be helpful:
https://odysee.com/@TechBuild:a/Control-3-wire-turnouts-from-2-wire-controllers:6?r=BfPRP8QNYHTeiN8UXAAVGDojhQYUz7yU
Reply 1 year ago
Thank you Mr Kushagra Ji for giving me a very important information. Once I go back, I will try out the same and give you a call, till then have a great time and bye for now. Take care.
Reply 1 year ago
Glad to help.
Reply 1 year ago
Thanks for the help you are going to give me. Once I reach my home back I will send you my contact number, so that we will be able to talk directly face to face. Most probably in June we will be visiting Allahabad, Varanasi, at that time will definitely try to meet en-route. Have a great time ahead.
Reply 1 year ago
OK. Thank you.
4 years ago
Great stuff.
Just what I am looking for my Christmas train layout.
May I ask you if you could amend the program for two trains to run alternatively in opposite directions ?
(No way that I can learn to code b4 this Christmas)
rgds, John
Reply 4 years ago
Here you go:
https://www.instructables.com/id/Run-Two-Trains-on-an-Automated-LayoutVariation-1/
Reply 4 years ago
Sure!
4 years ago
Good work, very simple and nice.
Reply 4 years ago
Thanks! More such projects coming in the future!
4 years ago
Cool!))
Reply 4 years ago
Thanks for your feedback! It motivates me to keep creating such projects. Stay tuned! More projects coming in the future.