2.Obstacle Avoidance

In this tutorial, you can make the car smartly detect and avoid obstacles, making for a smoother, collision-free driving experience.

 

 

Installing the Ultrasonic Sensor

The key to our car's new abilities lies in an ultrasonic sensor. This sensor will help your car 'see' obstacles in its path. To start, connect the ultrasonic sensor to Grove port 4 on your Robo Pico. 

 

If you're unsure how to do this, don't worry. The connection diagram below shows the minimum connection requirement for this lesson.

 

Setting Up the Software

We will need a new script from our Github repository to give your car its obstacle avoidance abilities. If you haven't yet downloaded the files or need to re-download them, you can do so here.

 

Next, copy the content of the '02_Obstacle_Avoidance.py' file and paste it into the 'code.py' file on your Raspberry Pi Pico W. 

 

The '02_Obstacle_Avoidance.py' script will instruct your BocoBot Car to use the ultrasonic sensor to detect any obstacles in front of it. If it detects something in the way, the car will smartly turn left, avoiding any potential collision.
 

อุปกรณ์ฮาร์ดแวร์