|
arduino IDEArduino
|
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 member, I made this project. 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.
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 many 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
Follow the circuit schematic from the previous step and 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!
/*Arduino program to run two trains alternatively on an automatd layout.
*By Tech Build: https://www.youtube.com/channel/UCNy7DyfhSD9jsQEgNwETp9g?sub_confirmation=1
*
*/
int i=0; //Integer to store the locomotive's speed at a scale from 0 to 255.
int a=4;// Integer to store the delay(in seconds) for halting the first train, needs to be varied depending upon the length of the track between the sensor and the required halting location of the train.
// Increase the value of 'a' if the first train stops before reaching the starting position. Reduce it if the train stops too far ahead.
int b=11;// Integer to store the delay(in seconds) for halting the second train, needs to be varied depending upon the length of the track between the sensor and the required halting location of the train.
// Increase the value of 'b' if the second train stops before reaching the starting position. Reduce it if the train stops too far ahead.
void switch_to_pass(){
digitalWrite(11,LOW);
digitalWrite(12,HIGH);
delay(200);
digitalWrite(12,LOW);
}
void switch_to_main(){
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
delay(200);
digitalWrite(11,LOW);
}
void motor_go(){
if(i>=1){
analogWrite(10,0);
analogWrite(9,i);
}
if(i<=-1){
analogWrite(9,0);
analogWrite(10,(i*-1));
}
if(i==0){
analogWrite(9,0);
analogWrite(10,0);
}
}
void setup() {
pinMode(A0,INPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
}
void loop() {
switch_to_pass();//Switching turnouts to the siding since the train will start the journey fro there.
for(i=0;i<=40;i++){//Increasing the speed of the first train to 40, at this speed the lights turn on but the train remains at rest.
motor_go();
delay(10);
}
delay(2000);//Waiting for 2000 milliseconds or 2 seconds(1000 milliseconds equals to 1 second).
for(i=i;i<=90;i++){//Increasing the speed of the first train to 90.
motor_go();
delay(500);
}
delay(4000);
for(i=i;i<=180;i++){//Increasing the speed of the first train to 180.
motor_go();
delay(250);
}
delay(3000);
for(i=i;i!=90;i--){//Decreasing the speed of the first train back to 90.
motor_go();
delay(500);
}
delay(2000);
while(digitalRead(A0)==LOW);//Waiting for the first train to cross the sensored track.
delay(1000*a);//Waiting for the first train to enter the siding.
for(i=i;i!=60;i--){//Reducing the speed of the first train gradually.
motor_go();
delay(500);
}
for(i=i;i!=40;i--){//Reducing the speed of the first train gradually, bringing it to a halt.
motor_go();
delay(250);
}
for(i=i;i!=0;i--){
motor_go();
delay(62);
}
delay(2000);
/*
* The first train has completed its loop and has stopped.
* The second train will now prepare to start.
*/
switch_to_main();//Switching turnouts to the second route since the second train will start the journey fro there.
for(i=i;i!=-40;i--){//Increasing the speed of the second train to 40, at this speed the lights turn on but the train remains at rest.
motor_go();
delay(60);
}
for(i=i;i!=-90;i--){//Increasing the speed of the second train to 90.
motor_go();
delay(250);
}
delay(4000);
for(i=i;i!=-180;i--){//Increasing the speed of the second train to 180.
motor_go();
delay(250);
}
delay(4000);
for(i=i;i!=-90;i++){//Decreasing the speed of the second train back to 90.
motor_go();
delay(250);
}
delay(4000);
while(digitalRead(A0)==LOW);//Waiting for the second train to cross the sensored track.
delay(1000*b);
for(i=i;i!=-80;i++){//Reducing the speed of the second train gradually.
motor_go();
delay(500);
}
delay(2000);
for(i=i;i!=-40;i++){//Reducing the speed of the first train gradually, bringing it to a halt.
motor_go();
delay(500);
}
delay(1000);
for(i=i;i!=0;i++){
motor_go();
delay(60);
}
delay(2000);
/*
* The second train has completed its loop and has stopped.
* The first train will now prepare to start.
*/
}
Automated Model Railroad Layout Running Two Trains
- Comments(0)
- 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...
-
-
-
kmMiniSchield MIDI I/O - IN/OUT/THROUGH MIDI extension for kmMidiMini
124 0 0 -
DIY Laser Power Meter with Arduino
173 0 2 -
-
-
Box & Bolt, 3D Printed Cardboard Crafting Tools
162 0 2 -