Below you find a closeup of the train buffer with the Mindstorms touchsensor. If the wagon hits the buffer, the NXT brick sends a message to the train that it should stop, and to proceed to the decoupling phase.
In the Youtube video you see a test run:
- Train drives towards the train buffer
- Wagon hits the buffer
- NXT brick sends message to the NXT on the train.
- Train stops
- Train starts decoupling of the wagon
- Train drives away
Note: in the final version, the train should slow down before hitting the buffer stop.