The code and instructions for making a level crossing for one or more tracks. It has four gates and flashing lights.
The code is complete. You do not have to either know nor do any coding. You may, of course, make changes but it is presented ready to run. You can see it in operation below.
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.
The controlling sketch can be changed to increase or decrease the number of tracks. You may also add flashing lights to the gates.
The action is intimated by IR sensors located on the East and West sides of the crossing. The sensors are under track, between ties, with the usual 5mm detector attached LEDss changed to remote 3mm detectors.
This crossing is part of our USING ARDUINO FOR FUN SKETCHBOOK that contains this and many other ready to run Arduino projects.
In that sketchbook there are other level crossing projects that may interest you:
How To Install An IR Sensor Under Track – Shows you how to install the sensors without a lot of work under the layout and, at the same time, in a way that they are not easily notice.
The gates on the road crossing entrance and road crossing exit close at different times. This mimics the prototypes that allow vehicles that are on the tracks to properly exit when the entrance gates start to close.
Multiple trains can be in the crossing at the same time. The gates will not open until the last train leave the protected area.
After the sensors signal that the last train has left the protected area, there is a 20 second delay (adjustable) to ensure that the signal detected all cars in the consist.
You can use this for one or more tracks. The upper limit it the number of pins on your Arduino board. The board used in this project is an Arduino Nano.
For a single road lane crossing, just eliminate the road exit gate.
For you convenience, the code is available on Pastebin at this link. Click here.
Live Code Simulation
This link takes you to the WOKWI code simulator where you can test the sketch. Click Here.
The images below show the circuit board.
Note that there are 4 resistors that are not connected. If you wish to have flashing lights on your gates, it is just a matter of adding wires to the appropriate pins. The pins are shown in the program.
There is a gap shown in the image. That ensures that the entrance and exit gates can be controlled separately.
I used perf board. You might find it easier to use vero board and arrange the pin headers to take advantage of the continuous strips.
Servos x 4
Resistors x 2 If you are going to add flashing lights to the gates you will need a total of 6
Arduino Board – A Nano is fine.
IR Sensors – 2 for each track
Female Dupont Pin Headers
Mechanical Pin Headers
3mm replacement IR Sensitive LEDs
You can get all these parts in a package at this link.
Related Level Crossing Pages
Bells For Level Crossing Flashing Lights
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.