What is the Speed of Your Layout? – Part 3, Automation Solution


I had used Arduino microcontrollers for some animation and lighting effects on the basement HO layout at our last house. These are great little devices designed in Italy which are intended for hobbyists and artists who need a simple way to translate some sort of input (push button, switch, accelerometer, thermometer, light sensor, GPS sensor, etc.) into some sort of output (LED or light bulb to flash, DC motor, servo, sound to play, LCD display, etc.).

To get started with Arduinos I purchased an excellent kit for around $100 from Canada Robotix which contains about 15 separate projects and all the necessary electronic parts, as well as very clear instructions and the basics of the programming language C++ which tells the device how to behave. I have no computer programming experience, but it was easy and a lot of fun to learn the Arduino. Programming is done on your personal computer using freeware and the code (“sketch” in Arduino parlance) uploaded to the Arduino through a USB cable. There are thousands of people around the world who offer solutions to problems and advice on Internet forums and even share the code they have written for their projects.

There are several Arduino models suitable for various applications but the model I used for this application is the Pro Mini which can be purchased for as little as $5 a copy if you shop around online. The following picture is enlarged - actual dimensions are 33 millimeters (1.3 inches) by 18 millimeters (0.7 inches).


I used two Arduino microcontrollers for my automation solution. One Arduino controlled the motor speed using outputs from the other which identified where the train was on the layout.

I first buried several light sensors in the ballast between the rails at intervals around the track. Each sensor was about 4 millimeters (1/8 inch) wide, so they were easy to hide. When a sensor was shaded by the presence of a train, the Arduino mounted under the layout powered by a 9-volt battery caused an LED mounted immediately beneath the layout, thus under the train, to shine on the ground. If the layout was turning exactly in sync with the train each LED shined 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, making you disoriented, 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 was then wired in series with the electrical supply to the motor described above. One tripod was 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 turned, if no LED shone on either tripod it meant that the train was located correctly because it was between the two tripods. If the layout was going slower than the train (which always travels at a constant speed), the train would drift ahead, causing the LED under the locomotive to shine on the front tripod. The Arduino would then slightly increase the speed of the motor turning the layout which, in turn, caused the train to drift backward. Conversely, if the layout was going faster than the train, the train would drift backward, causing the LED under the caboose to shine on the rear tripod. The Arduino would then slightly reduce the speed of the motor turning the layout which, in turn, caused the train to drift ahead.

When the layout and the train were first turned on, the train “hunted” back and forth for a few minutes between the tripods and would even overshoot as the Arduino adjusted the speed of the layout to match the speed of the train. Once at equilibrium, at train shows the layout would 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 I was able to depict 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 detected the light of the LEDs from under the layout. This helped me explain to guests what was going on when they showed more than a passing interest. The real-time data feed to the Excel graph was by way of the Arduino’s serial port.

This was a fun problem-solving exercise and a great learning experience. The layout was entertaining at train shows because of the conversations I had with inquisitive children and interested adults; there were occasional squeals of delight – from the children, that is. I have no training in human psychology, but I found it fascinating to observe the reactions of various people – some had no clue as to what was going on before their eyes, while others figured it out quickly.

Note: you may have noticed that the above post is written in the past tense. I completed the layout in 2016 and had a lot of fun with it at train shows. However, after becoming an active participant in our Free-mo group I lost interest in the rotating layout. It sat on a top shelf in our garage under a dust cover. Over the 2018 Christmas season I reached the inevitable conclusion that the space could be freed up for other things so dismantled the layout. It was fun while it lasted and a great learning tool.