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

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

Update in progress.

Please Support Us By Looking At Our Shop
Please Support Use By Going Here.

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

There are two other pages with tutorials on making level crossings.

Level Crossings With Two Gates


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.

The code is at Multi-track Level Crossing With Four Gates –   You may preview it and download when you


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