(Warning: this is not for purists, I even had to cut one LEGO cable!)
A while ago I started playing with electronics combined with LEGO trains (http://www.eurobrick...22#entry2473697).
But also using an Arduino with LEGO is great fun, my first finished project is an automatic level crossing:
You can see two PF motors moving the barriers. An Arduino uses four reed switches to count the coupling magnets on two tracks - the barrier will open only if no train is between the reed switches. The PF motors are connected to an Arduino "Motor Shield". Both motors are connected to the same output. So I had to cut a PF cable - but I'm using both parts, since a PF battery box provides the power. Two red LEDs blink while the barriers are closed. The barriers are really fast, and closing them has higher priority than opening (you can see this in the video at 0:14).
The orientation of the reed switches is critical, so not every train is detected in every direction on every track. We used this at "Bricking Bavaria" and the second day we found a combination that worked and the level crossing worked from 10-17.