Obstacle Avoidance Robot Using Raspberry Pi Pico

In the previous article, we built an Obstacle Avoidance Robot using Arduino. We have planned to make the same Obstacle Avoidance Robot using a Raspberry Pi Pico microcontroller. In this project, I mainly used an HC-05 ultrasonic distance sensor to get the distance sensed immediately and drive the motors separately by the L298N motor driver module. Also, I used a robot car chassis for this project. But you can use a DIY chassis according to your budget.

You can learn how to Interface the ultrasonic sensor with the Raspberry Pi Pico board, please visit this link below.

Project

Obstacle Avoidance Robot Using Raspberry Pi Pico

Circuit Diagram

Obstacle Avoidance Robot Using Raspberry Pi Pico Circuit Diagram

Components Required

  • Raspberry Pi Pico
  • L298N Motor Driver
  • HC-SR04 Ultrasonic Sensor
  • Servo Motor
  • DC Gear Motor (x4)
  • Wheels (x4)
  • Robot Car Chassis
  • Connection Wires
  • Lithium-Ion Battery (x4)
  • 4-Channel Lithium-Ion Battery Holder
  • Breadboard

About Parts of the Obstacle Avoidance Robot

Raspberry Pi Pico
HC-SR04 Ultrasonic Sensor
L298N Motor Driver
Servo Motor
DC Gear Motor
Wheel
Chassis

Setup Robot Chassis for Obstacle Avoidance Robot

Let’s create the robot car chassis first. For that, see the below pictures for detail.

Obstacle Avoidance Robot Chassis

After that, install the DC motors as shown in the pictures below. You can arrange them as you like.

Obstacle Avoidance Robot DC Motor

Next, attach the wheels with the DC motors. For that, I used robot wheels.

Obstacle Avoidance Robot Battery Holder

Now, mount the L298N motor driver module on the robot chassis and connect all four DC motors to the motor driver.

Obstacle Avoidance Robot Motor Driver

Next, place the Raspberry Pi Pico on the breadboard.

Obstacle Avoidance Robot Raspberry Pi Pico

After that, attach the servo motor to the front of the chassis using hot glue or a screw. And then, install the ultrasonic sensor on top of the servo motor.

Install a lithium-ion battery on the battery holder and breadboard at the top of the robot car chassis.

Finally, connect the servo motor, ultrasonic sensor, motor driver module, and lithium-ion battery holder to the Raspberry Pi Pico.

Connect the Raspberry Pi Pico to the computer and upload the Python script to the board.

How to Prepare Thonny for Uploading Code to Raspberry Pi Pico Board

First, you have to install Thonny Python IDE on your PC. After installing it, hold and press the “BOOTSEL” button on your Raspberry Pi Pico board and plug it into your PC. Release the button when your computer detects your Raspberry Pi board.

Now you can see an extra storage device appeared in your my computer section. Open it and click the “INDEX” file and you will redirect to the Raspberry Pi website. From there, you have to download the “MicroPython UF2 file“. After that simply drag and drop to that extra storage and return to the Thonny software.

microPython UF2 file

Now you need to click on Tools > Options > Interpreter > select microPython (Raspberry Pi Pico) > select the correct port and hit OK.

Now copy and paste the below code to the Thonny IDE, and hit the green-coloured run button. Then you have to save the code as “main.py” (please save it as it is, otherwise the board will not work after USB is removed from the PC) on the Raspberry Pi. If you select My Computer then it will not work after you remove the board from the PC.

Raspberry Pi Pico Code

1 thought on “Obstacle Avoidance Robot Using Raspberry Pi Pico”

Leave a Comment