Simple Automated Point to Point Model Railroad

5,643

16

21

Introduction: 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!

Arduino Contest 2019

Participated in the
Arduino Contest 2019

Be the First to Share

    Recommendations

    • Fruit and Veggies Speed Challenge

      Fruit and Veggies Speed Challenge
    • Summer Fun: Student Design Challenge

      Summer Fun: Student Design Challenge
    • Fandom Contest

      Fandom Contest

    21 Comments

    0
    kcschamuhn
    kcschamuhn

    Question 14 days ago on Step 3

    Hi
    I can't find a link to your code for this

    0
    KushagraK7
    KushagraK7

    Answer 14 days ago

    There is a download button under step3, there you can find the Arduino code file fro download.

    0
    kcschamuhn
    kcschamuhn

    Reply 14 days ago

    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?

    0
    KushagraK7
    KushagraK7

    Reply 14 days ago

    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

    0
    KushagraK7
    KushagraK7

    Reply 14 days ago

    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.

    0
    kcschamuhn
    kcschamuhn

    Reply 14 days ago

    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?

    0
    kcschamuhn
    kcschamuhn

    Reply 14 days ago

    thank you I found it

    0
    NoicaBoica
    NoicaBoica

    Question 2 months ago

    Hello love your project but unfortunate when i tried to recreate it it wasnt working and i think the voltage is to low for my train to start. How do i correct that in the arduino code.

    0
    KushagraK7
    KushagraK7

    Answer 2 months ago

    You can try increasing the value of variables 'MidSpeed' and 'MaxSpeed' which are given at the beginning part of the code. The maximum value can be 255 which will make the train go very fast, so try with values like 60 for 'MidSpeed' and 150 for 'MaxSpeed'.
    I hope this helps.

    0
    JFB3
    JFB3

    4 months ago

    Hi,
    Very nice project. I am wondering if this setup can be used with only one sensor. Like the train would start full power and slow down and stop after a sensor is triggered then wait a few seconds and go again. All forward direction. Is that possible with the setup?

    0
    MetalMilkMan
    MetalMilkMan

    Question 10 months ago

    Hey, just wanted to ask (As a non model train hobbyist), I am trying to set a camera(as part of a streaming setup) to rotate on an Arc. One of the ways I have thought to do this would be to use a small scale rail set with the camera and enough slack on top of it to move along a track of 90cm at a slow velocity. Do you think it would be possible for an 'engine' to support the weight of a webcam 200g using a programmed track like this? Thank you for any advice.

    0
    KushagraK7
    KushagraK7

    Answer 10 months ago

    I believe a strong enough locomotive like a diesel one with 6 wheels on each truck can move the camera. If you have an HO-scale setup, it is even better. I would recommend you to fix the camera on a wagon or a flat-car and attach that to the locomotive.
    All the best!

    0
    Neo_B
    Neo_B

    11 months ago

    Cool idea - I'm going to try this weekend. Should I increase the power for HO Scale train? If yes what is the power you would recommend (US)- tks

    0
    KushagraK7
    KushagraK7

    Reply 11 months ago

    I had used a 12-volt 1Amp(~12 Watt) DC adapter for powering up the setup. This adapter can be enough for running a single HO-scale locomotive but I would recommend getting a 12-volt 2Amp adapter to stay on the safe side.

    0
    5172ken
    5172ken

    Question 2 years ago on Step 10

    Great project...but I can't see where the sketch reverses the trains direction. All seems to work OK, but in only one direction.

    0
    KushagraK7
    KushagraK7

    Answer 1 year ago

    The direction of the train depends upon whether the value of the variable(int s) responsible for the speed of the train is +ve or -ve.

    0
    audreyobscura
    audreyobscura

    2 years ago

    This is a cool project, and the train is so adorably tiny!

    0
    AshishC44
    AshishC44

    Reply 2 years ago

    So nice of you
    .....very confusion with power supply....Vin and Gnd from Arduino why not supply to direct to Arduino....to driver

    0
    KushagraK7
    KushagraK7

    Reply 2 years ago

    The power supply adapter is connected to the Arduino board's power connector which is connected to the pins VIN and GND of the board, in that way, the Arduino board allows the motor driver board's power connection terminals to connect to the power supply's connector.