Anti Collision arduino train

Hi i would like to know if its possible to make an anti-collision train using and IR sensor.

If so,is there any examples made as i am just starting to learn how to use Arduino Program.

I am trying to code somewhat similar to this link:

Yes, You can do it, and it will be very easy to make...
A very easy way to do it for a beginner would be to read the sensor values, when it detects something it will give you a value.

Normally the value will start to decrease as it gets close and when it reaches a desired distance you can just activate a relay that will cut the train motor power.

For a beginner thats a easy way on how to do it.