|
arduino IDEArduino
|
Automated Model Railroad Layout With Reverse Loops
In one of my previous projects, I showed how to make a Simple Automated Point to Point Model Railroad. One of the main disadvantages of that project was that the train had to move in the reverse direction for going back to the starting point. Running a train in that layout meant that it had to run in reverse with the locomotive at the back. So, in this project, let's learn to make a similar layout with a reverse loop at each end so our train can run in the forward direction all the time. Let's get started!
Step 1: Watch the Video
Watch the above video to get a better understanding of this project.
Step 2: Get All the Required Stuff
For this project, you will need:
Electronic supplies:
- An Arduino microcontroller compatible with the Adafruit Motor Shield V2. (1)
- An Adafruit Motor Shield V2.
- 2 'Sensored' tracks.
- 10 male-to-male jumper wires.
- A 12-volt DC power source.
Model railroad supplies:
- 2 turnouts(One for each reverse loop).
- 3 track feeders(One for mainline and the rest two each for a reverse loop).
- 4 insulated rail joiners(Get 4 more if the turnout being used don't have a "Power Routing" feature).
1. Any R3 Arduino board such as UNO, Leonardo, and similar ones can be used. Boards like Mega can also be used with a slight modification(Get help here).
Step 3: Program the Arduino Microcontroller
I would recommend going through the Arduino code to get a deeper understanding of how the code works in making the train run around the layout.
Step 4: Replace the Rail Joiners of the Turnouts
If the turnouts being used have a "Power Routing" feature then only the outermost rails need to be electrically isolated using insulated rail joiners. If the turnouts being used don't have this feature, all 4 rails need to be electrically isolated.
Step 5: Set Up the Layout
The 'sensored' track will be installed at the entrance of each of the reverse loops. The mainline and the two reverse loops each will have a separate feeder track.
Decide which one of the loops will loop A and B. The loop into which the train will enter first on startup will be loop A and the other will be loop B. So, the turnout in loop A will be turnout A, and on in loop B will be turnout B.
Step 6: Install the Motor Shield on the Arduino Board and Connect the Track Power and Turnouts
Turnouts:
Both the turnouts need to be connected in parallel but in opposite polarities so that they always switch in the opposite directions.
- Connect the turnout A to the motor shield as shown in picture 4.
- Connect the turnout B to the motor shield as shown in picture 5.
Track feeders:
The track feeders for both the reverse loops need to be connected in parallel with the same polarities so that the train moves in the same direction in both the loops, i.e., entering in from the branched line of the turnout and leaving from the straight side(Watch the video in Step 1 for clarification).
- Connect the mainline's feeder power wires to the motor shield as shown in picture 5. Make sure the polarity of the connection is such that the train moves into loop A on startup.
- Connect the loops' feeders' power wires to the motor shield as shown in picture 6.
Step 7: Connect the Sensors
Connect the sensors' -ve pin to the 'GND' header and the +v pins to the +5-volt header. The 'IQREF' pin of an Arduino board can also be used as a +5-volt connection to power sensors for boards working on a logic voltage level of 5-volts.
Connect the sensor's output pin adjacent to the first reverse loop to the input 'A0' of the Arduino board and the output pin of the sensor adjacent to the second reverse loop to the input pin 'A1' of the Arduino board.
Step 8: Double-check All the Wiring Connections
Make sure all the wiring has been done correctly and no connections are loose.
Step 9: Connect the Setup to Power
You can either connect the Adapter to the Arduino board's female DC jack connector or you can use the terminal block on the motor shield to power up the setup.
Step 10: Place the Train/locomotive on the Mainline
Using a rerailer tool is highly recommended, especially for steam locomotives. Make sure that the wheels of the locomotive and the rolling stock(If using) are properly aligned with the track.
Step 11: Power Up the Setup
Step 12: Watch Your Train Go
After powerup, the turnout in loop A should switch to side and the turnout in loop B should switch to straight. After then, the train/locomotive should start to proceed toward loop A.
If something goes wrong, power down the setup immediately to prevent the motor drivers from getting fried.
Step 13: Troubleshoot If Required
If particular turnout switches in the wrong way, reverse the polarity of its connection. Do the same for the track power feeders if the train starts to move in the wrong direction.
If the setup resets after a while after startup even when the turnouts are switching correctly, check the polarity of connection of the track feeders of the reverse loops and make sure the current is flowing in the correct direction, reverse the polarity if needed.
Step 14: Go Furthur
After you have got your project working successfully, why not tinker with it? Change the Arduino code to suit your needs, add more features, and maybe a passing siding? Or run multiple trains? Whatever you do, all the best!
/*
Arduino program to automate a continous-running single-track model railroad layout with
reverse loops.
Made by TechBuild: https://www.youtube.com/channel/UCNy7DyfhSD9jsQEgNwETp9g?sub_confirmation=1
Feel free to modify the code to suit your layout.
*/
#include<Adafruit_MotorShield.h>//Make sure this library is installed in your IDE.
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *mainline = AFMS.getMotor(1);//Connected to the single-track mainline's feeder.
Adafruit_DCMotor *loopline = AFMS.getMotor(2);//Connected to the two reverse loops' feeders.
Adafruit_DCMotor *turnout = AFMS.getMotor(4);//Connected to the reverse loops' turnouts connected in parallel.
#define sensorA A0//Sensor on mainline at the entrance of the first reverse loop.
#define sensorB A1//Sensor on mainline at the entrance of the second reverse loop.
int s;//Variable for storing the speed of the locomotive(0 to 255, from stop to max speed).
int tripCount = 2;//Number to trips the train will make around the layout.
int i;//Variable for use in a for() loop for tripCount.
//All the below values should be in the range of 0-255.
//Most locomotives don't start to move until 30.
//Speed vales greater than 180 might be too much for a model railroad.
int StandBySpeed = 35;//Speed at which the locomotive's lights turn on while it is still at rest(Not all locomotives can do this!).
int SlowSpeed = 60;//Speed at which the locomotive will start to move.
int FastSpeed = 90;//Maximum speed of the locomotive.
//Function to set the speed and direction of the locomotive on the mainline depending on the
//vlaue and the sign(+/-) of the variable 'sp', ranging from -255 to 255.
void mainlinePwr(int sp)
{
if (sp > 0)
{
mainline->setSpeed(sp);
mainline->run(FORWARD);
}
if (sp < 0)
{
mainline->setSpeed(-sp);
mainline->run(BACKWARD);
}
if (sp == 0)
{
mainline->setSpeed(sp);
mainline->run(RELEASE);
}
}
//Functions to switch the turnouts to staright or side.
/*When this function is called(activated), the turnout in the first reverse loop must switch
to straight and the turnout in the second reverse loop must switch to side.
*/
void turnout_straight()
{
turnout->run(FORWARD);
delay(50);
turnout->run(RELEASE);
}
/*When this function is called(activated), the turnout in the first reverse loop must switch
to side and the turnout in the second reverse loop must switch to straight.
*/
void turnout_side()
{
turnout->run(BACKWARD);
delay(50);
turnout->run(RELEASE);
}
/*
Custom function made to wait for the train to pass the 'sensored' track connected to the
input pin declared in the bracket(in the place of int i in void loop()).
The sensor's output does not remains steady HIGH when a train is passing over it.
This can be observed by the flickering light of the sensor when the train crosses over it.
This means that the earlier used while() statement can't be used here.
To slove, it a for() loop is made which waits for the sensor output to remain_track low for
a long enough time to ensure that the train has crossed the 'sensored' track.
When the train crosses the 'sensored' track, the ocasional flicker of the LED(Meaning that
sensor is sending digital HIGH signals to the Aruino board.) causes the loop to reset.
This loop ends only sfter the complete train has crossed the 'sensored' track.
*/
void waitToPass(int q, int t) { //Variable q 'tells' which sensor to consider.
//Variable t 'tells' the clearance delay(in seconds).
int a;
while (digitalRead(q) != HIGH);
b:
for (a = 0; a != 1000 * t; a++) {
if (digitalRead(q) == HIGH) goto b; //If the sensor output turns HIGH in between the for() loop, it will start over.
delay(1);
}
}
void setup() {
// put your setup code here, to run once:
AFMS.begin(960);
loopline->run(FORWARD);//Set the direction of current in both the reverse loops.
//This will remain constant forever.
turnout->setSpeed(255);//Allow maximum voltage(=supply voltage) to be applied to the turnouts whenever they need to be switched.
//Switches the turnouts in both the directions on startup.
//This can help check if the turnouts arr working or not.
turnout_straight();
turnout_side();
//Set pins for the sensors as digital inputs.
pinMode(sensorA, INPUT);
pinMode(sensorB, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
for (s = 0; s != StandBySpeed; s++)
{
mainlinePwr(s);
loopline->setSpeed(s);
delay(30);
}
delay(2000);
for (s = s; s != SlowSpeed; s++)
{
mainlinePwr(s);
loopline->setSpeed(s);
delay(125);
}
//
/*
The below loop will go on until the value of the variable 'i' matches the value of the
variable 'tripCount', i.e., until the train makes the set number of trips around the layout.
*/
for (i = 0; i != tripCount; i++)
{
while (digitalRead(sensorA) != HIGH);
waitToPass(sensorA, 4);
mainlinePwr(-s);
turnout_straight();
for (s = s; s != FastSpeed; s++)
{
mainlinePwr(-s);
loopline->setSpeed(s);
delay(125);
}
while (digitalRead(sensorB) != HIGH);
waitToPass(sensorB, 4);
mainlinePwr(s);
turnout_side();
}
//
for (s = s; s != SlowSpeed; s--)
{
mainlinePwr(s);
loopline->setSpeed(s);
delay(250);
}
while (digitalRead(sensorB) != HIGH);
waitToPass(sensorB, 1);
for (s = s; s != StandBySpeed; s--)
{
mainlinePwr(s);
loopline->setSpeed(s);
delay(60);
}
delay(2000);
for (s = s; s != 0; s--)
{
mainlinePwr(s);
loopline->setSpeed(s);
delay(60);
}
delay(5000);//Wait for a set amount of time before starting the entire process again.
}
Automated Model Railroad Layout With Reverse Loops
- Comments(2)
- Likes(0)
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by KushagraK7
- Raspberry Pi Pico RC Vehicle SuppliesA Raspberry Pi Pico(Almost any microcontroller can be used here, but the Pico offers great f...
- Stepper Motor Controlled Stepper Motor Without Microcontroller! Step 1: Watch the VideoWatch the video to get a full understanding of the project and learn how to t...
- Automated Model Railroad Layout Running Two Trains I made an Automated Model Train Layout with Passing Siding a while back. Upon request from a fellow ...
- Program the Raspberry Pi Pico With the Arduino IDE The Raspberry Pi Pico is a recently launched product in the family of microcontrollers and its load ...
- Reuse an Old Laptop's Touchpad to Control a Computer! PS/2 laptop touchpads are among the coolest user interface devices to use with a microcontroller. Th...
- Automated Model Railroad Layout With Reverse Loops In one of my previous projects, I showed how to make a Simple Automated Point to Point Model Railroa...
- Use a Stepper Motor As a Rotary Encoder Rotary encoders are great for use in microcontroller projects as an input device but their performan...
- Keyboard Controlled Model Train(PS/2 Interface) Using Arduino microcontrollers, there are a lot of ways of controlling model railway layouts. A keyb...
- Stepper Motor Speed and Direction Control Without a Microcontroller In one of my previous projects, I showed you how to control a stepper motor's speed using a 555 time...
- Smartphone Controlled 4X4 Robot With ESP8266 SuppliesFor this project, you will need:An ESP8266 microcontroller(Node MCU)A dual H-bridge motor dr...
- Touchpad Controlled Digital Servo Motor Here is a quick and simple project where we control a digital servo motor with the slide of our fing...
- Smartphone Controlled Model Railroad With an ESP8266 IntroA while back, I made a project where a stepper motor's position is controlled using a smartphon...
- Simple USB Volume Controller with Arduino This project uses a rotary encoder connected to an Arduino Leonardo to control the audio volume of a...
- Motor Speed and Direction Control with a Web-Server using an ESP01 Supplies:For this project, you will need:An ESP01 microcontroller(You can use any ESP8266-based micr...
- Wi-Fi Controlled Stepper Motor With an ESP Microcontroller Step 1: Get All the Required StuffFor this project, you will need:An ESP8266 microcontrollerA Steppe...
- Simple Automated Model Railroad Loop With Yard Siding Video:Supplies: For this project, you will require:An Arduino microcontroller board compatible with ...
- Laptop Touchpad Controlled Model Railroad Supplies:For this project, you will require:An Arduino microcontroller compatible with Adafruit Moto...
- Control a Stepper Motor with a Slide of Your Finger Supplies:An Arduino microcontroller boardA PS/2 touchpad from a laptop(Try to get one with a Synapti...
-
-
-
3D printed Enclosure Backplate for Riden RD60xx power supplies
42 0 0 -
-
-
-
Sega Master System RGB Encoder Switcher Z80 QSB v1.2
47 0 0 -
18650 2S2P Battery Charger, Protection and 5V Output Board
60 0 0 -
High Precision Thermal Imager + Infrared Thermometer | OpenTemp
362 0 5 -
Sony PlayStation Multi Output Frequency Oscillator (MOFO) v1
117 0 2