Train Detection and Signal Control
I am working on a modest layout (see New to the Scene) and I am now at the stage where I would like to add entry and exit signals at the two stations in the layout. I first thought of making my own signals, but N-scale quickly presents its special challenges due to its smallness. Achieving scale-correct appearance of objects is often difficult or impossible without special materials or manufacturing methods. Although my theme is Switzerland with SBB and BLS trains, I found the Viessmann signals, while modeled after the German railway system, very similar in appearance to the Swiss signals, and very nicely made on top of it.
My trains run on an analog system that I designed before the advent of DCC, and I can run 8 different locomotives independently. But the capability of DCC running all sort of ancillary equipment is naturally missing in my system. I am also not interested in running trains automatically with a block system controlled by signals as the layout is too small to run two trains in sequence on the same track. Even realistically long trains are not really feasible.
So, if the signals are not used to control the trains, perhaps the train controlling the signal is a realistic alternative. The signal is normally red and as the train approaches, the signal turns green and then returns to red once the train has passed. If a train approaches from the opposite direction (while shunting for example), the signal must remain red.
This requires detection of the train before and after the signal, of course. There are many ways to detect the presence of a train, infrared optically, magnetically with reed switches buried in the track and magnets attached to the train underside, with ultrasound sensing, or by sensing the locomotive current which is probably the least obtrusive method. The diagram below shows the live track separated into a block before and one after the signal. Each block is re-fed via a current-sensing transformer that mirrors the locomotive current to a sensing circuit which then controls the signal.
The Arduino platform is well suited to process the locomotive mirror current and to control the signal. It is also reasonably priced. The Uno has 6 analog inputs and 14 digital inputs/outputs whereas the Mega has 16 analog inputs and 54 digital input/outputs. The Uno could control 2 signals (not enough digital ports for 3), and the Mega could control up to 8 signals. The signal control program is quite straight-forward.
This train detection method works for AC and DC, provided the DC is not smoothed.