Obstacle detector

How can I detect an obstacle with sensor on bolt?

You can detect any obstacle with the help of IR transmitter and Receiver.
When an obstacle blocks the infrared rays emitted by the transmitter, the receiver is not able to receive those and hence an obstacle is detected.
There is an IR Sensor module available in the market for the same.

That depends how you want to sense the obstacle. You can use IR sensor, PIR or even ultrasonic sensor for detection.

@Riddhesh_Misal You can use infrared sensor if you want a compact setup and wants to keep the price of the project low.
The IR sensor has 2 components first,transmitter it transmits infrared light and second,receiver it generates a potential difference across its terminal when a infrared light falls on it this potential difference is read by the op-amp and then amplified to a specific voltage which the micro controller takes as a input.
OR you can use ultrasonic sensor which works exactly like IR sensor but it uses ultrasonic sound waves to identify the object in front of it. When the waves bounces back from the object its is detected by the receiver .
The main difference between the IR and Ultrasonic sensor is IR sensor mainly provide digital values like high and low and isn’t that reliable but the Ultrasonic sensor provides the analog data which means how far is the object and is quite accurate for short distances.That is why ultrasonic sensor is costlier than infrared sensor