I made this simple system for the toy trains of my little baby.

It is really simple.

The BOM (Bill Of Materials)
1 – Arduino UNO board
2 – Some wires
3 – A piece of thin cane
4 – A servo motor
5 – a bicolor led

Connect your components as shown in the following picture, then use some glue to put together the thin cane with the servo motor.

rail crossing

The following short video shows my system in action

The last step is to load the sketch into the Arduino UNO board.
This is the code for the sketch: