Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES ここでご購入を!

In this lesson, our Raspberry Pi robot car will use Ultrasonic sensor to detect obstacles and make automatic driving and avoid collision.

No. Picture Device Qty. Accessories Link
1 Ultrosonic Sensor 1 M1.4*8 Screw x 4
M1.4 Nut x 4
Click here to buy
2 Servo Motor 1 M2.2*8 Self Tapping Screw x 2
M2*4 Self Tapping Screw x 1
Click here to buy
3 Mount Holder for Ultrasonic Sensor 1 M1.4*8 Screw x 4
M1.4 Nut x 4
M2*4 Self Tapping Screw x 1
Click here to buy
4 10Pin jumper wire female to female 20cm some
5 Philips screwdriver 1 Click here to buy

Step 1: You must complete Lesson1 and Lesson 2

Step 2: Install servo motor at the front of upper car chassis with 2pcs M2.2*8 self tapping screws.

Step 3: Install ultrasonic module to mount holder with 4pcs M1.4*8 screw and M1.4 nuts

Step 4:Install ultrasonic holder on micro servo motor with 1pcs M2*4 self tapping screw.

Connect ultrasonic sensor holder SG90 servo motor to PWM 14 port of OSOYOO PWM HAT board, and connect GND and VCC of ultrasonic module to GND and 5V of OSOYOO PWM HAT board, then connect TRIG and ECHO of ultrasonic module to GPIO20 and GPIO21 of raspberry pi as following graph (Remember : DO NOT remove any existing wires installed in Lesson 1 ):

Download the python code by typing following command in your Raspberry Pi terminal:

wget http://osoyoo.com/driver/servo-steer-car/pi-obstacle.py 

Turn on the battery of your car and  your servo and run the program,

If you are using Python 2 in Raspberry Pi  , type:

python pi-obstacle.py

Your servo will rotate the ultrasonic sensor to front position for 3 seconds. If your sensor is not facing front direction, please turn off the battery or press Ctrl-C key to stop the program. Then remove the sensor from servo and re-install it, make sure it faces front and fix the position with screw, now your can type same command  python pi-obstacle.py  and run the program again.

Now the car will automatically make obstacle avoidance auto driving.