Inspiration

My main hobby is model railroading. I'm a member of the Kentucky & Indiana Model Railroad Club in Louisville and wanted to add flashing railroad crossing lights to several crossings of the club's layout. Existing commercial DIY crossing control systems that I'm aware of do not operate a crossing as realistically as I would like and generally have serious limitations as to their applications.

What it does

Photocells embedded in the model railroad track detect train movements and turn on and off flashing railroad crossing in a manner that accurate simulates real railroad crossings.

An Approach photoresistor detects a train passing overhead, activating the crossing lights as it approaches. If the train stops before reaching the crossing, it will time out and deactivate the crossing. If the train occupies the center two photoresistors (placed directly on either side of the crossing), the crossing will not deactivate, and will reactivate if the train had previously taken too long to reach the island. Using the order in which the island is cleared, the controller knows which direction the train is traveling and temporarily disables the approach detection from that direction so that the train does not reactivate the crossing erroneously as it continues away. When everything is cleared for long enough, the crossing then full resets itself to wait for the next train.

The detection logic is done per track modularly so that the logic of operations on one track will not conflict with that of any other tracks.

How we built it

The brains of the system is an Arduino Mega which continuously monitors photoresistors embedded in the model railroad tracks, and then uses that information to determine a train's position and direction of travel, flashing the crossing lights as deemed appropriate. It has the ability to turn the lights on in advance of an approaching train and quickly turn them off when the train has cleared, as well as the ability to deactivate itself if a train approaches but stops before occupying the crossing. It can adjust for a train stopping on the crossing and then reversing in the opposite direction as well.

The code is written flexibly to allow for easy configuration of a controller to detect train movements on up to 4 tracks and control flashing lights on up to 4 crossings. (Configurations can be maximum 4 single-track crossings, 2 double-track crossings, 1 double-track and 2 single-track crossings, 1 triple-track and 1 single-track crossings, or 1 quad-track crossing.) The demo is configured for 1 double-track crossing.

Challenges we ran into

Writing the logic to interpret the train motion and direction was my biggest challenge and very time consuming. It also took me a good amount of time to assemble all the hardware, and the code had to be calibrated for the photoresistors as different levels of ambient light throughout the day affect their outputs.

Accomplishments that we're proud of

Anything sort of functions at all considering how much logic it requires and how little sleep I've been "functioning" on while trying to write it.

What we learned

I had never written code using a Task Scheduling format before, but learned how to do so, allowing for several interdependent functions to be performed "simultaneously."

What's next for Modular Automatic Model Railroad Crossing Controller

I intend to design and fabricate custom Arduino Mega Shields compatible with the code and install several of these systems to control flashing lights on the Kentucky & Indiana Model Railroad Club's layout.

I would also like to add the ability for the controller to operate a bell sound effect in addition to the flashing lights and support for operating crossing gates using servo motors. I'm also considering an upgraded version that uses infrared emitters and detectors for train detection instead of photocells, which would make it possible to operate trains with the lights turn off in the room for "night" operations without the system erroneously activating the crossing.

Built With

Share this project:

Updates