Hi Guys,
I just did some testing and found out that the problem could be with the Proximity sensor.
I connected my arduino directly to the 12V dc and my proximity sensor to another separate 12v source and everything worked well.
I think the sensor cannot be connected in parallel with the arduino.
Sorry for troubling you all Thank You for your assistance