Arduino Multi-Track Level Crossing With Four Gates Flashing Lights And Alarm Bells

An Arduino project for installing a gated level crossing over multiple tracks.

More than one train can be passing through the crossing at any one time and it will operate properly.

 

Grade Crossing And Other Layout Animation Video Tutorials

This series of videos gives you a start with layout animation.  To stay up to date and be notified as we add to this series, subscribe and click on the bell in one of the videos below.

 

Some types of sensor can trigger multiple times with one train, like optical sensors that see every wagon. To deal with this an ‘end of train’ detection is built in. If the departure sensor is triggered, a timer is started. If the sensor triggers again before the timer was at zero, the timer resets again. When the timer reaches zero, the software decides this was the end of train.

Such timer is not 100% fail safe. When a train stands still while the optical sensor beam is right in between two wagons, ‘end of train’ may be given falsely. Chances of this happening are very slim though and at the moment I don’t know of another way to detect ‘end of train’ without using additional sensors. A workaround is to place the sensor beam diagonal.

Of course with multiple tracks it is possible another train is coming while the cycle that blinks the LEDs and closes the gate is already running. To handle this, a train counter is introduced, which is incremented each time a new train is detected and is decremented when an ‘end_of_train’ is detected. When the counter reaches zero the gates open and the cycle stops.

Code Simulation.

 

The code is a on  Pastebin

Materials Required For Arduino Level Crossing

arduino nanoArduino Nano, Uno, Or Mega – Analog pins can be used as digital pins so all that you really need is a Nano.

 

 

 

 

df player proDFPlayer Pro –  Get the DFPlayer plus Speakers here.

Load with bells sounds that you get free here.

 

 

 

 

 

 

 

Speaker – Get the DFPlayer plus Speakers here.

 

 

 

 

LEDs – If you buy your lights and gates, they will probably come with lights installed.

If you make your own flashing lights, use either SMD or 3 or 4 mm Leds.

SMD LEDs are flat faced so you make a more realistic looking light. 0603 or 0803 work fine in HO scale. Wire them yourself or buy them prewired.

There is a complete selection of LEDs at this link.

 

 

 

 

 

 

 

 

 

 

 

  • Resistors – For the lights you need a resistor on each.

 

 

 

 

 

IR sensor – Two of these are required per track,  You can use them as they come, but we recommend some changes, described here.

IR sensors are available here.

 

 

 

3mm ir leds3mm IR LEDs – We recommend strongly that you use these.  They are available here.

 

 

 

Servo – Tower pro Micro servo 9g SG90.

Get them here.

 

 

 

Prototype Board

 

 

Pin Headers

 

Wire – Telephone cable wire is fine.

Gates  – Buy or make your own.  To make your own, go here.

Roadside Lights – Buy or make your own – To make your own, go here.

It is easier to get a complete selection of most of  these at one time at  Kits

 

Making The Crossing

I recommend that you make a simple prototype on a piece of styrofoam. Work out all the bugs there.  It will save you a lot of time and grief.  Once you are satisfied, then transfer what you have done to your layout.

Plan Your Control Panel –

Replace the IR LEDs on the IR detectors.  The procedure is here.

Load the bell sounds on your DFPlayer and test that it works.  The procedure is here.

Set your servo angles and make control wire extensions.   Go here.

level crossing circuit boardMount the DF Player, Nano and Pin Headers on the vero strip  board.

 

 

 

 

 

Load the sketch on the Nano.

Lay some test track on the styrofoam and install the IR Detector LEDs under the track.

Connect everything and test it by rolling a car through the crossing.

If it works the first time, consider yourself lucky.  Debug.

Now install the servos under the styrofoam and check that the gates work. Adjust and debug.

 

 

 

 

 

 

 


We hope that you found the information in this page useful. The internet is all about getting and giving. And giving back is the best. Please donate $1 or more to aid us in our continuing quest to add to and polish the information in our site.


Scroll to top