Home » Projects » Electronics Projects » Model Railroad Control with Arduino

Model Railroad Control with Arduino

model railroad control

Put your Arduino to work in your model railroad control. A great combination.

My friend Rupert James has been using an Arduino for model railroad control for a few years now. He started out using Arduino for lighting and animation effects. Rupert began with the Starter Kit and absolutely no computer background. He is now writing control sketches in C++ and having a lot of fun.

His latest project is a model train moving on a track going around a mountain that is also moving. As the mountain rotates, the model train’s speed matches the mountain’s rotation speed. So, to the observer, the train stays in the same place. Since this train is pulled by a working model of a steam engine, there are a lot of moving parts (connecting rods and valve  gears to enjoy.) Rupert’s analogy is that the action is like walking on a treadmill.

This setup is used to provide public demonstrations of model railroading – particularly to students. I am sure that the young folks also enjoy learning that they can use their Arduino for model railroad control.

Model Railroad Control – How This Project Works

Rupert explains:

“I used two Arduino microcontrollers for an automation solution. One Arduino controls the motor speed using outputs from the other which identifies where the train is on the layout.

I first buried several light sensors in the ballast between the rails at intervals around the track. Each sensor is about 4 mm wide so they are easy to hide. When a sensor is shaded by the presence of the train, the Arduino mounted under the layout powered by a 9 volt battery causes an LED mounted immediately beneath the layout, thus under the train, to shine on the ground. If the layout is turning exactly in sync with the train each LED shines on one spot, as if stationary. By way of analogy, if you walk on a treadmill and shine a flashlight on the ceiling above you, the beam remains in one spot – until you stare at the ceiling too long which causes you to fall off the back of the treadmill and hit yourself in the face with the flashlight.

I then acquired two inexpensive camera tripods and mounted a PVC electrical box on each. I put a light sensor in the top of each box. These are wired to the second Arduino microprocessor housed inside one of the electrical boxes which is then wired in series with the electrical supply to the motor described above. One tripod is positioned under the layout just ahead of the desired position of the locomotive and the other just behind the desired position of the caboose. As the layout turns, if no LED shines on either tripod it means that the train is located correctly because it is between the two tripods. If the
layout is going slower than the train (which always travels at a constant speed), the train will drift ahead, causing the LED under the locomotive to shine on the front tripod. The Arduino will then slightly increase the speed of the motor turning the layout which, in turn, causes the train to drift backward. Conversely, if the layout is going faster than the train, the train will drift backward, causing the LED under the caboose to shine on the rear tripod. The Arduino will then slightly reduce the speed of the motor turning the layout which, in turn, causes the train to drift ahead.
When the layout and the train are first turned on, the train “hunts” back and forth for a few minutes between the tripods and even overshoots as the Arduino adjusts the speed of the layout to match the speed of the train.

At train shows the layout will run with the train in the correct place for the entire six to eight hours of the show without any attention or need for adjustment. I have an old notebook computer that I can plug into the stationary Arduino located in the tripod. Using Microsoft Excel it graphically depicts in real time the speed of the layout in scale km/hr, the average scale speed and the times when the front and rear tripod sensors detect the light of the LEDs from under the layout. This helps me explain to guests what is going on when they show more than a passing interest.

This was a fun problem solving exercise and a great learning experience. The layout is good fun at train shows because of the conversations I have with inquisitive children and interested adults; there are occasional squeals of delight – from the children, that is.”

Well done, Rupert. (His project is described in full in the March 2016 edition of Highball! The Official Publication of the 6th Division of the Pacific Northwest Region of the National Model Railroad Association.)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.