Simple Automated Point to Point Model Railroad

12K1942

Intro: Simple Automated Point to Point Model Railroad

Arduino microcontrollers are great to automate model railroad layouts. Automating layouts is useful for many purposes like putting your layout up at a display where the layout operation can be programmed to run trains in an automated sequence. The low cost and open source Arduino microcontrollers and the widespread community make it easy and simple to make projects and program them.

So, without further ado, let's get started!

STEP 1: Watch the Video


Watching the video can help you get a fair idea of how this works.

STEP 2: Get the Parts and Components

Here is what you will need:

  • An Arduino microcontroller board.
  • An L298N motor driver module.
  • 2 'sensored' tracks.
  • 6 male to female jumper wires(A set of 3 wires each to connect the sensors pins to the Arduino board's digital I/O pins and power.)
  • 3 male to female jumper wires(To connect the motor driver's input pins to the Arduino board's digital I/O pins.)
  • 2 male to male jumper wires(To connect the motor driver to power and ground connection.)
  • 2 male to male jumper wires(To connect the motor driver's output terminals to power the track rails.)
  • A 12-volt power supply(Current capacity should be at least 1000mA or 1A for N-scale.)

STEP 3: Program the Arduino Microcontroller

Get the Arduino IDE from here. You may need to make some adjustments to the Arduino code for your layout.

STEP 4: Make a Test Layout

Click on the above picture to get more information.

Make a layout with bumper tracks at each end. The length of the mainline track between the stations can be made as long as required. Since the train slows down after crossing the 'sensored' track and continues to move for some distance, make sure there is a sufficient length of track between the 'sensored' tracks of each points A and B and their bumper tracks. The above picture might be useful for a reference.

STEP 5: Make Wiring Connections for the Motor Driver

Make the following wiring connections:

  • Connect the motor driver's input pin 'IN3' to the Arduino board's digital output pin 'D8'.
  • Connect the motor driver's input pin 'IN4' to the Arduino board's digital output pin 'D9'.
  • Connect the motor driver's input pin 'ENB' to the Arduino board's digital output pin 'D10'.

Connect two male to male jumper wires to the terminals marked 'GND' and '+12-V' and connect them to the pins marked 'GND' and 'VIN' of the Arduino board respectively.

Connect two male to male jumper wires to the output terminals of the motor driver and connect them to the track rails through a power feeder track.

STEP 6: Wire Up the Sensors to the Arduino Board

Connect both the sensors' 'VCC' and 'GND' pins of the sensors to the '+5-volt' and 'GND' pin of the Arduino board. You might need to get a bit creative to connect two 'VCC' connection jumpers to a single '5-volt' pin available on the Arduino UNO. Connect the 'OUT' pin of the sensor of station 'A' to the Arduino board's pin A0 and the remaining sensor's pin to the Arduino board's pin A1.

STEP 7: Place a Test Locomotive on the Tracks

For testing purposes, place any locomotive or a powered car on the point 'A' of the layout from where the locomotive or the powered car will start.

STEP 8: Connect the Setup to Power Source and Power It Up

Connect the Arduino board's power input connector to a 12-volt power source and turn it on.

STEP 9: Watch Your Train Operate Autonomously


If everything was done correctly, you should see your test locomotive or powered car start from point 'A', speed up after crossing the first 'sensored' track it approaches, slow down and stop at point 'B' after crossing the second 'sensored' track, start again after a few seconds in the opposite direction, speed up after crossing the first 'sensored' track it approaches, and slow down and stop at point A after crossing the 'sensored' track installed near point 'A'. It will wait for a few seconds before starting the entire process again.

If the locomotive starts to move in the wrong direction, interchange the wires connected to the track power from the output of the motor driver.

STEP 10: What's Next

Try tweaking the Arduino code to run the trains as per your wish, try adding more functions to the layout by combining my previous projects with this one. Whatever you do, all the best!

34 Comments

I cannot get my loco to move from one end of the track to the other. When I don't plug in the sensors, seems to me the loco should move at constant speed from one end to the other. Mine slows down and stops before reaching end of track. Both directions.
I notice your sensors have the bulbs along the track. I put mine transverse. Does it matter?
Can you share a picture of your sensors?
When I run the train from a to b without using the sensors, it goes to within 3' of b (track length is about 20 ft), stops and reverses back to a. Then reverses, goes to within 3' of b, etc. Voltage goes to 8-9 v about half way along, then reduces to 0, reverses, goes up to 8-9 v about half way along, then reduces to 0 again.
I believe the voltage reaches only that values because the train isn't set to go at full speed in the code. If the track voltage were to be 12-volts, the train would move way too fast to look realistic.
what puzzles me is not the voltage but why it increases half way down the track and then decreases to zero before the train gets to the end of the track
Well, the microcontroller is programmed to do that. The train is meant to start slowly from one point, speed up, and move through the middle section and when it approaches the other end, it will slow down and stop. So, when the train is speeding up, the voltage will gradually rise to speed up the train and will reduce to slow it down.
The speed of the train basically depends on the supplied voltage.
I will, but it shouldn't make any difference as to orientation to the track. Just if it's covered or not.
I got the thing working fine, but after a few runs the loco stops part way down the track, then reverses, goes back to the beginning but spins its wheels. Then it starts over, and goes only part way down the track, stops and reverses.
Make sure that the sensors are not getting exposed to too much light and getting triggered. You might need to reduce their sensitivity.
I am unable to get your program to work. The train moves from A through the sensor A0 (I tried setting it to low as someone else did), goes half way down the track, then stops. Same thing if A0 is set to high. After a while it reverses, goes back to A and spins its wheels. I was looking forward to using arduino to automate a back and forth trolley. I will have to try something else.
When I attach the output wires to the track I get only 1 volt across the tracks. ?? Any ideas?
I hope the problem has been resolved.
thank you - that particular problem has been resolved. still a way to go to get it up and running properly. challenging - things aren't working like on your video. but we'll get there....
Hi
I can't find a link to your code for this
There is a download button under step3, there you can find the Arduino code file fro download.
thank you
in your code you have "void setup: put your setup code here, to run once." is the code you have there to run continuously? I am not a coder at all. what code is needed to run continuously?
I would highly recommend you to learn to program Arduino. The Arduino IDE is an easy-to-learn, yet powerful platform for programming microcontrollers. There are a lot of resources available and after you have learnt, you will be able to do a lot of things with microcontrollers in model railways
The part of code in "void loop()" runs continuously, this part is enclosed within curly braces.
I have programmed the microcontroller so that it runs the operation continues in a loop, the train stops for 5 seconds at each of the endpoints, you can also increase or decrease this duration by changing the value of the variable 'ta' and 'tb' which can be found in the beginning of the code.
I think I found in your instructions that the train will run continuously. what code is needed to stop the process? or do I just unplug things?
More Comments