How to make an automatically controlled point to point model railroad control system for a DC powered layout or diorama.
This system varies the speed of the train as it travels it route and allows you to set the time that the train remains at the endpoint before starting on the return journey.
The system relies on ir sensors near the endpoints. When a train that is approaching and endpoint triggers the sensor, it begins to slow and stops after your predetermined time.
When the train leaves the endpoint, it slowly speeds to your predetermined speed. After it triggers the sensor, it speeds up to your predetermined maximum speed.
You can automate a very short stretch of track such as that which you might find in a diorama.
Materials Required
Other than wire, you need 2 IR sensors, an Arduino Nano (or above), a 12 volt, amp DC power supply and an LN298N motor controller, plus the program of course. You can get that all in kit form here.
How To Wire The Controller
This is the wiring diagram that shows you how to connect the various parts.
Make the following wiring connections:
Nano To L298N
- 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’.
IR Sensors To Nano
Point A Output to A0
Point B Output to A1
VCC on both to Nano 5v
GRND on both to common ground
System Power
Connect 12 v DC power to Nano Vin and Ground
Track Power
Connect from L298n output to track.
The Track Plan
Make the length of the layout as long as you wish.
The location of the sensor LEDs depends on the length of your track.
So lay out your track. Be sure to put bumpers on each end of the track.
If the layout is temporary, you can simply lay the sensors alongside the track. Alternatively you can make a sensor track for temporary layouts.
Testing
We are going to test how the program works meaning where the train stops – plowing into the bumper or not.
Connect all the wires and power up.
The train will start running at the default speeds and start slowing at the default rate.
Note the what happens and power down before you slam the engine into the bumper.
Adjust Train Speeds And Times
In the program thee are some settings:
int ta – this sets the time the train will run before stopping at Point A after it triggers the Point A sensor.
int tb – this sets the time the train will run before stopping at Point B after it triggers the Point B sensor.
int sa – this sets the time the trains remains at Point A before it returns to Point B.
int sb – this sets the time the trains remains at Point B before it returns to Point A.
Int MidSpeed – the speed at the sensor when entering or leaving a point.
int MAXSpeed – the maximum speed between sensors.
To change the distance the train travels when it is slowing down, change the times int ta and int tb.
And remember, you can also move the IR sensors to a point where the train stops before it hits the bumper.
After setting the distance, adjust the speed.