Arduino Level Single Track Crossing With Two Gates Flashing Lights And Alarm Bells

A model railroad level crossing with gates, flashing roadside lights and optional alarm bells and flashing gate lights.

A complete tutorial  with the Arduino sketch, materials list, wiring instructions,  and video demonstration of sketch performance.

Arduino Level Crossing
Arduino Level Crossing

If you want a level crossing with four gates and the same options, go to  Level Crossings With Four Gates

If you don’t want all the options offered by this sketch, you do not have to change the code.  Just don’t add the wires on your prototype board. An image of that is below.

The flashing gate lights are eliminated by commenting them out where indicated in the sketch.

The alarm bells are added by connecting a bells module that is activated by an IR sensor. Information about that module and how to set it up are here.  (The page is in process of being updated)





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.




LEDs – If you buy your lights and gates, they will probably come with lights installed.  If you make your own, 3 or 4 mm Leds are appropriate.  You can also use colored smd LEDs or pixels.  If you use the either of the latter two, the face will be flat.  You will have to add some colored extension to get a realistic look.








  • Resistors –







IR sensor – You can find them cheap searching eBay for “IR Infrared Obstacle Avoidance Sensor Module for Arduino” You can get them at any of the marketplaces.








Servo – Tower pro Micro servo 9g SG90 Again available in all the marketplaces.








Prototype Board







Wire – Telephone cable wire is fine.

Gates  – Buy or make your own.  To make your own, see (updating)

Roadside Lights – Buy or make your own – To make your own, see (updating)

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


Level Crossing Arduino Sketch

The code is in Pastebin at this link.  You can easily review it and download it. It will come to you in ASCII format so you can load it directly into your IDE.

Wiring Instructions For Arduino Level Crossing

The wiring is quite simple.

Servo control wires attach to  pins 3 and 4

Ir detector wires attach to pins 5 and 6

LED flashers to pins 10 & 11 and 12 & 13 .

The servo and IR detector + and – connect to an external 5 v dc power source.



Level Crossing Video Demonstration

The video is in processing.




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


level crossing arduino instruction
Click on image to watch sketch in action

This video shows the crossing in action;  Click on the image or click here.






This tutorial is part of our series Arduino Projects.  There is a video playlist at Playlist

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