By Loren Blaney
A FLASHER, GATE, AND BELL FOR YOUR MODEL
The intersection of a train track
with a road provides a natural
focal point of interest. Why not
take advantage of it with a
crossing signal that flashes and a
gate that lowers when a train
passes? This simple PIC
microcontroller circuit even
enhances the action with a
realistic bell sound!
■ PHOTO 1. An N. J. International
signal is activated as an HO train
To activate a signal, you need a way to
detect approaching trains. Model railroaders
have developed several methods over the years.
For larger, heavier trains various configurations of
mechanical switches can be used. However, most train
layouts rely on more complicated methods, such as
photodetectors or circuits that sense the current drawn by
an engine in an electrically isolated section of track. The
method described here uses magnetic reed switches.
They’re simple, inexpensive, and easy to install and conceal.
Their one drawback might be that they require magnets
mounted on the engine and caboose (or other tail-end car).
When an engine approaches a road crossing, its
magnet closes the contacts of a reed switch hidden in the
track. This sends a signal to a PIC that alternately flashes a
pair of LEDs, pulses a servo motor that slowly lowers a gate,
and sends digitized samples of a ringing bell to a speaker.
The action continues until a second reed switch buried at
the road crossing detects the passing of the caboose.
want to start with just one flashing signal and add the gates
and speaker later. Please note that there is only enough
power to operate LEDs and not incandescent bulbs.
A 7805 regulator provides the required five volts. It
accepts a wide variety of input voltages — both AC and DC
— but is typically driven from the 18 VAC accessory power
provided by most train transformers. The relatively large 470
µF capacitor on the output provides momentary surge
power for the servo motors. The 220 ohm resistors on the
PIC’s output lines not only limit the current for the LEDs, but
also protect the PIC from short circuits if connectors are
plugged in wrong or wires on the layout are shorted. The
22K pull-up resistors are required for inputs on port C, but
not port A since it has built-in pull-ups. The 82 ohm resistor
limits the maximum current drawn by the 100 ohm speaker.
The 5K pot provides a volume control. The 1.0 µF cap filters
out most of the aliasing noise in the bell waveform which is
sampled at 8 kHz.
The schematic and board layout in Figures 1 and 2
reveal the simple circuit. It’s basically a PIC with a bunch of
I/O connectors and a power supply. A PIC16F684 was
chosen because it’s inexpensive, comes in an easy to handle
package (DIP), and has support for pulse-width modulation
(PWM) which is used for the bell sound. The circuit will
drive two sets of flashers and two servos, so automobile
traffic is protected in both directions. Of course, you can
use any combination of the outputs. You might, for instance,
42 October 2011
Begin by gathering all the parts and necessary tools.
Solder in the shorter parts first. Install the 14-pin IC socket
for U2, being sure to orient it correctly. Install the two 220
ohm resistor networks RN1 and RN2. Don’t confuse their
locations with the six-pin locations used for sockets S1 and
S2. Tape is useful to hold the connectors in place while
soldering. Mount the 1.0 µF capacitor, C4, on-end.