Since I'm automating lego trains, an automated level crossing can't miss in the layout. So I built one with some spare parts. I first wanted to use the 7866 remote controlled level crossing as a basis but think that the bars don't go up/down very nice: too fast and sudden. Then I discovered two micro motors I had laying around and started designing the whole thing. There are two sensors: when the train activates the first sensor, the bars will be lowered. When the last wagon activates the last sensor, the bars will go up again. In the meantime the lights will go on/off.
The program is "intelligent": it can tell which sensor is activated first so the level crossing can be used in both directions. I wanted to draw the power for the system from the rails but unfortunately the motors of the trains produce a lot of electronic noise which disturbed the microcontroller and I wasn't able to filter it out.
Let me know what you think of it!
PS: for those who are interested, a how-it-works-video is work in progress ;)