First attempt to control DC motor using my Raspberry Pi B+ .the motor spin freely till the measured distance is less than 8 cm.
the ultrasonic sensor is responsible for measuring the distance. I have written the code that control the motor and measure the distance using Python .