reset, so we can use a start and finish value later to get
very accurate real time. When the back of the train finally
clears the outer most sensor (E1), it records a “finish” time
and computes the speed.
Speed is dependent on your scale, and by changing
the scale factor (87 for HO scale, 48 for O, etc.), this
scheme will work for any model railroad big or small. The
computation of scale speed takes the milliseconds of
elapsed time, the distance traveled in inches, and the scale
of the model, and turns it into a scale MPH. The same
sequence occurs for a train going eastbound with only a
difference in the displayed train direction.
The LCD uses the built-in library of the Arduino to
produce the display shown for a westbound train. After a
delay, the display goes back to a clear block.
Making All Model
If you enjoy realistic animation as one more facet of
model trains, you can give it a big lift by using a
microprocessor and servos. In the larger scales, the
commercial crossing gates and moving accessories are
usually driven by a solenoid. It’s way too “jerky” to be
realistic, and begs for the installation of a servo to slow it
down. It would be fairly simple to rebuild the device with
a servo attached, then slow down the motion and change
the timing to come on and off like we did with the
flashers in this project. Look around your layout. There are
■ FIGURE 4. Overall program logic for the flasher/
Microprocessors and Model Trains
Meet Head On!
In order to bring the hardware and software together, a
mockup was needed on the bench. Track sensors (LDRs) were
mounted in a strip of plywood. A piece of prepainted track
roadbed from another project was on hand and worked out just
fine. The LCD — which would eventually be mounted in the track
framework fascia near the flashers — was also tied to the
Arduino Uno with plug ended jumpers.
After software debugging and speedometer time checks, the
entire unit is ready for mounting and permanent wiring. It works
for any scale model railroad and fits in a very small amount of
■ PHOTO A. Screen display after a train has passed.
■ PHOTO B. The flasher on the model railroad.
The LCD screen fits into the fascia nearby.
August 2015 31