For my entry in the Bitify Your City contest, I automated a Lego railroad with a crossing gate and station stop since a good rail system is vital to a thriving city.
The crossing gate uses a Long LED and Light Sensor bit to detect when the train approaches a crossing. An Arduino Bit measures the light value from the sensor and when it drops below a threshold, it triggers a Servo Bit to lower the gate and blinks a pair of LEDs on the crossing sign in an alternating pattern. After a couple seconds, the Arduino raises the gate and turns off the LEDs.
I found that the cables for the Long LEDs were too short and a little stuff to work with for the crossing sign, so I made a pair of custom longer LED cables. I found some old wires with the same connector as the Long LED in a bin of parts I salvaged from broken electronics and soldered LEDs to them.
Connecting the Servo Bit to Lego was a bit of a challenge. I found that the mounting holes on the servo
can clip onto Lego pole pieces to hold it in place. To connect the servo to a Lego gear, I used some thin wire to tie the round horn to the gear, but needed a small washer between them, otherwise the wheel would be slightly crooked and turn unevenly. The servo turns more than 90 degrees, so I had to use a pair of two differently sized gears to get the crossing gate to turn 90 degrees.
The station stop also uses a Long LED and Light Sensor Bit to detect the passing train. When triggered, the Arduino uses an IR LED Bit to stop the train at the station platform for a few seconds and then starts the train back up again. I found an Arduino library online for generating the right IR pulses to control a Lego Power Functions receiver.