Arduino project · Motors and movement · Medium
Railway Crossing Gate
When a train comes closer than 60 cm the gate lowers, the red light shows and the bell sounds.
What you will learn
- How a gate is automated
- How a distance sensor detects a train
- How several outputs follow one condition
How it works
When the sensor sees an object closer than 60 cm, the servo goes to 0 degrees (gate down), the red LED comes on and the buzzer sounds. When the track is clear the gate goes up to 90 degrees.
Try this next
- Add a second sensor on the other side of the track.
- Make the red lights flash alternately.
- Add a delay so the gate opens a few seconds after the train passes.
The simulator program and explanation on this page are original. The idea follows a classic Arduino project that students have built for years.
Parts: sensors and actuators (tap to show or hide)
Try the inputs (virtual sensors)
Pins (you can change them)
| Part | Arduino pin (change it here) | How to wire it |
|---|
Every wire, one by one
Red rail = 5 V from the Arduino 5V pin. Black rail = GND. The coloured wires carry signals. Match the wire colours on the drawing to this list.
| # | Colour | From (part and leg) | To |
|---|
Steps run from top to bottom, then start again. While the simulation runs, the active step is highlighted in green.
Quantities come from the parts you added. The store links open a search for that item on Robu.in, Amazon.in and ThinkRobotics, so you always see what is in stock today. Check the model, voltage and price before you order.
| # | Item | Qty | Search term | Buy / compare |
|---|
The PDF has the circuit sketch, pin table, every wire, sequence, full code, the parts list with store links, do’s and don’ts for each part, and the safety notes. The project file lets you come back and keep editing.
In the real world
A railway level crossing
Move the distance slider. When the train comes close, the gate lowers, the red lights flash and the bell rings, as at a real railway crossing.
Tip: use the gold tab at the bottom of the circuit drawing to pull the real-world view up over the Arduino board. Your parts stay visible above it, so you can press a button and watch the real scene react.
- Distance sensor = how close the train is
- Servo = the gate arm
- Red LED = the flashing warning lights
- Buzzer = the crossing bell