PiCar-X Self Driving AI Robot with Raspberry Pi 4
Raspberry Pi 4 AI Self Driving Robot PiCar-X has camera, ultrasonic, line tracking sensor for color/face/signs detection with Python Code
- Suitable forB.Tech/Diploma Raspberry Pi students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
Overview
The
PiCar-X
is an
AI self-driving robot
car that uses
Raspberry Pi
as its control center. The Robotic Kit is designed by
SunFounder
. The Kit comes with a
Robot HAT
for Raspberry Pi. The HAT integrates the
motor driving, servo driving
, and preset ADC, PWM, and digital pins to extend the functionality.
The PiCar-X’s has a
2-axis camera
module,
ultrasonic module
, and
line tracking modules
that can provide the functions of
color/face/traffic signs detection, automatic obstacle avoidance, automatic line tracking
, etc. There is already a speaker in the Robot HAT to facilitate
TTS (Text-to-Speech)
, sound effects, background music, etc. All of the PiCar-X functions, including
GPIO control
, computer vision, and deep learning, are implemented through the open-sourced
Python programming
language, OpenCV’s Computer Vision Library software, and Google’s TensorFlow for deep learning frameworks.
In this tutorial, we will go through the details of
PiCar-X Robot Kit
with Raspberry Pi. We will go through the Robot Assembly process & a method to use
Raspbian OS
with the System. We will install various
dependencies
and
libraries
for using all the sensors and modules with the Robot. We will then
calibrate
the motors and test some sensors part before implementing the full final applications. Later using the Robot and
Python Code
, we can make the following Robots:
Obstacle Avoidance Robot
Line Tracking Robot
Text to Speech Robot
Video Car Robot
App Controlled AI Robot
Bill of Materials
We need the following components along with the
SunFounder Robot Car Kit
. You can purchase all these components from Amazon links:
S.N.
Components
Quantity
Purchase Links
Raspberry Pi Ai Car Kit PiCar-X
Amazon
SunFounder
Raspberry Pi 4
Amazon
SunFounder
Samsung 18650 Battery
AliExpress
SD Card 16/32 GB
Amazon
SunFounder
SD Card Adapter
Amazon
AliExpress
18650 Battery Charger
Amazon
AliExpress
Robot HAT cannot charge the battery, so you need to buy a battery charger at the same time.
Component List & Robot Assembly
The Kit comes with all the necessary components required for the Robot which include the following components:
You need to buy a Raspberry Pi 4 Board and a pair of Samsung 18650 Batteries separately.
The most important part of this Kit is Robot HAT. With the Robot HAT board, the PiCar-X integrates left/right driving motors, servo motors for steering, and the camera’s pan/tilt functions, and pre-sets the Robot HAT’s ADC, PWM, and Digital I2C pins to allow for extensions to the standard functionality of the Raspberry Pi.
Both a
speaker
and a
Bluetooth
chip have been engineered into the Robot HAT for remote control of Text-to-Speech, sound effects, or even background music functionality.
RST Button:
A short-press of the RST Button will cause any running programs to reset. A long press of the RST Button until the LED lights up, and then releasing will disconnect the Robot HAT’s Bluetooth chip.
USR Button:
The functions of the USR Button can be configured through programming. (Pressing down leads to an input of “0”, and releasing produces an input of “1” )
LED:
Configured through programming (Outputting ‘1’ turns the LED on, Outputting ‘0’ turns the LED off.)
Battery Indicator:
Battery voltage above 7.8V will light up the two indicator LEDs. Battery voltage ranging from 6.7V to 7.8V will only light up one LED, voltage below 6.7V will turn both LEDs off.
Bluetooth Indicator:
The Bluetooth indicator LED will stay on with a solid Bluetooth connection, and blink rapidly during signal transmission. The LED will blink at 1-second intervals if the Bluetooth is disconnected.
Left Motor Port & Right Motor Port:
These ports are used to connect the left and right motors.
Power Port:
A power port accepts an input voltage of 7-12V. A pair of Lithium-Ion batteries is a good choice to power the entire board.
Power Switch:
This switch is used to turn on/off the entire Raspberry Pi System.
To assemble the components together and make a perfect Robotic Car you can follow the
Assembly Guide
. The PDF Document has all the images and a pictorial view for easy help with assembly.
Servo Motor & Sensor Connections
The
Picar-X Raspberry Pi Robot
has 3 servo motors Pan, Tilt & Steering Servo. It also has 2 sensors;
Ultrasonic Sensor HC-SR04
and
Grayscale Sensor Module
The
Pan, Tilt
, and
Steering Servo
are connected to the following Pins of Robot HAT.
Servo 1 (Pan)
RPI HAT
Servo 2 (Tilt)
RPI HAT
Servo 3 (Steer)
RPI HAT
VCC
5V
VCC
5V
VCC
5V
GND
GND
GND
GND
GND
GND
Signal
P0
Signal
P1
Signal
P2
The
Ultrasonic Sensor HC-SR04
is connected to the following pins of Robot HAT.
Ultrasonic Sensor
RPI HAT
VCC
3.3V
GND
GND
TRIG
D2
ECHO
D3
The
Grayscale Module
is connected to the following pins of Robot HAT.
Grayscale Sensor
RPI HAT
VCC
3.3V
GND
GND
Output1
A0
Output2
A1
Output3
A2
After Robot assembly, you may start the
Raspberry Pi OS
& program Setup part.
Note:
If the servos have been powered on through the Robot HAT after assembly, do not manually force the steering gear, as this could cause damage to the servo.
Raspberry Pi OS Installation & Setup
The Raspberry Pi is a low-cost, computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It is also used as a tool to learn Python programming.
Before moving to the Robotic project part, we need to set up the
Raspberry Pi Board
. For this, you need a
16/32 GB SD Card
. We need to install OS to the system stored in SD Card.
The OS installation part and setup part can be followed on
Raspberry Pi OS Setup
. But for this robotic project part, it is recommended to install
Raspberry Pi OS(Legacy)
, this will allow you to go to the
Raspberry Pi desktop
to view the footage taken by the
camera
You can either use the
HDMI Screen
or enable
SSH
and connect the Raspberry Pi to
VNC Viewer
using the local IP Address, username, and password.
In my case, I am using the
Putty Software
to connect to my Raspberry Pi remotely. I am also using the VNC Viewer to set up the Python programming with Thonny.
Now we need to install many modules and dependencies to the system.
Installing Python Modules & Libraries
The
Picar-X Robot
should be turned ON and Raspberry Pi should be connected to the network. Now let’s install all the Python Modules and libraries.
Lets first update the system using following commands.
sudo
apt
update
sudo
apt
upgrade
Then install the Python3 related packages.
sudo
apt
install
git
python3
pip
python3
setuptools
python3
smbus
Download & install the libraries for
Robot-Hat
cd
/
/
pi
/
git
clone
https
:
//github.com/sunfounder/robot-hat.git
cd
robot
hat
sudo
python3
setup
py
install
Running ‘
setup.py
‘ will download some necessary components. Your download may have failed due to network issues. You may need to download it again at this point. See the following interface, type ‘
Y
‘, and press Enter.
Now, download and install the ‘
vilib
‘ module.
cd
/
/
pi
/
git
clone
https
:
//github.com/sunfounder/vilib.git
cd
vilib
sudo
python3
install
py
Similarly download and install the ‘
picar-x
‘ module.
cd
/
/
pi
/
git
clone
b
v2
https
:
//github.com/sunfounder/picar-x.git
cd
picar
sudo
python3
setup
py
install
This will download a large number of files, therefore it will take time.
Once the download is complete, run the ‘
i2samp.sh
‘ script to install the components required by the i2s amplifier, otherwise the picar-x will have no sound.
cd
/
/
pi
/
picar
sudo
bash
i2samp
sh
Type ‘
y
‘ and press enter to continue running the script.
Type ‘
y
‘ and press enter to run ‘
/dev/zero
‘ in the background.
Type y and press enter to restart the Picar-X.
After restarting, the Raspberry Pi will connect to the Network and will play a sound.
If there is no sound after restarting, you may need to run the ‘
i2samp.sh
‘ script several times.
All the install
The
PiCar-X
is an
AI self-driving robot
car that uses
Raspberry Pi
as its control center. The Robotic Kit is designed by
SunFounder
. The Kit comes with a
Robot HAT
for Raspberry Pi. The HAT integrates the
motor driving, servo driving
, and preset ADC, PWM, and digital pins to extend the functionality.
The PiCar-X’s has a
2-axis camera
module,
ultrasonic module
, and
line tracking modules
that can provide the functions of
color/face/traffic signs detection, automatic obstacle avoidance, automatic line tracking
, etc. There is already a speaker in the Robot HAT to facilitate
TTS (Text-to-Speech)
, sound effects, background music, etc. All of the PiCar-X functions, including
GPIO control
, computer vision, and deep learning, are implemented through the open-sourced
Python programming
language, OpenCV’s Computer Vision Library software, and Google’s TensorFlow for deep learning frameworks.
In this tutorial, we will go through the details of
PiCar-X Robot Kit
with Raspberry Pi. We will go through the Robot Assembly process & a method to use
Raspbian OS
with the System. We will install various
dependencies
and
libraries
for using all the sensors and modules with the Robot. We will then
calibrate
the motors and test some sensors part before implementing the full final applications. Later using the Robot and
Python Code
, we can make the following Robots:
Obstacle Avoidance Robot
Line Tracking Robot
Text to Speech Robot
Video Car Robot
App Controlled AI Robot
Bill of Materials
We need the following components along with the
SunFounder Robot Car Kit
. You can purchase all these components from Amazon links:
S.N.
Components
Quantity
Purchase Links
Raspberry Pi Ai Car Kit PiCar-X
Amazon
SunFounder
Raspberry Pi 4
Amazon
SunFounder
Samsung 18650 Battery
AliExpress
SD Card 16/32 GB
Amazon
SunFounder
SD Card Adapter
Amazon
AliExpress
18650 Battery Charger
Amazon
AliExpress
Robot HAT cannot charge the battery, so you need to buy a battery charger at the same time.
Component List & Robot Assembly
The Kit comes with all the necessary components required for the Robot which include the following components:
You need to buy a Raspberry Pi 4 Board and a pair of Samsung 18650 Batteries separately.
The most important part of this Kit is Robot HAT. With the Robot HAT board, the PiCar-X integrates left/right driving motors, servo motors for steering, and the camera’s pan/tilt functions, and pre-sets the Robot HAT’s ADC, PWM, and Digital I2C pins to allow for extensions to the standard functionality of the Raspberry Pi.
Both a
speaker
and a
Bluetooth
chip have been engineered into the Robot HAT for remote control of Text-to-Speech, sound effects, or even background music functionality.
RST Button:
A short-press of the RST Button will cause any running programs to reset. A long press of the RST Button until the LED lights up, and then releasing will disconnect the Robot HAT’s Bluetooth chip.
USR Button:
The functions of the USR Button can be configured through programming. (Pressing down leads to an input of “0”, and releasing produces an input of “1” )
LED:
Configured through programming (Outputting ‘1’ turns the LED on, Outputting ‘0’ turns the LED off.)
Battery Indicator:
Battery voltage above 7.8V will light up the two indicator LEDs. Battery voltage ranging from 6.7V to 7.8V will only light up one LED, voltage below 6.7V will turn both LEDs off.
Bluetooth Indicator:
The Bluetooth indicator LED will stay on with a solid Bluetooth connection, and blink rapidly during signal transmission. The LED will blink at 1-second intervals if the Bluetooth is disconnected.
Left Motor Port & Right Motor Port:
These ports are used to connect the left and right motors.
Power Port:
A power port accepts an input voltage of 7-12V. A pair of Lithium-Ion batteries is a good choice to power the entire board.
Power Switch:
This switch is used to turn on/off the entire Raspberry Pi System.
To assemble the components together and make a perfect Robotic Car you can follow the
Assembly Guide
. The PDF Document has all the images and a pictorial view for easy help with assembly.
Servo Motor & Sensor Connections
The
Picar-X Raspberry Pi Robot
has 3 servo motors Pan, Tilt & Steering Servo. It also has 2 sensors;
Ultrasonic Sensor HC-SR04
and
Grayscale Sensor Module
The
Pan, Tilt
, and
Steering Servo
are connected to the following Pins of Robot HAT.
Servo 1 (Pan)
RPI HAT
Servo 2 (Tilt)
RPI HAT
Servo 3 (Steer)
RPI HAT
VCC
5V
VCC
5V
VCC
5V
GND
GND
GND
GND
GND
GND
Signal
P0
Signal
P1
Signal
P2
The
Ultrasonic Sensor HC-SR04
is connected to the following pins of Robot HAT.
Ultrasonic Sensor
RPI HAT
VCC
3.3V
GND
GND
TRIG
D2
ECHO
D3
The
Grayscale Module
is connected to the following pins of Robot HAT.
Grayscale Sensor
RPI HAT
VCC
3.3V
GND
GND
Output1
A0
Output2
A1
Output3
A2
After Robot assembly, you may start the
Raspberry Pi OS
& program Setup part.
Note:
If the servos have been powered on through the Robot HAT after assembly, do not manually force the steering gear, as this could cause damage to the servo.
Raspberry Pi OS Installation & Setup
The Raspberry Pi is a low-cost, computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It is also used as a tool to learn Python programming.
Before moving to the Robotic project part, we need to set up the
Raspberry Pi Board
. For this, you need a
16/32 GB SD Card
. We need to install OS to the system stored in SD Card.
The OS installation part and setup part can be followed on
Raspberry Pi OS Setup
. But for this robotic project part, it is recommended to install
Raspberry Pi OS(Legacy)
, this will allow you to go to the
Raspberry Pi desktop
to view the footage taken by the
camera
You can either use the
HDMI Screen
or enable
SSH
and connect the Raspberry Pi to
VNC Viewer
using the local IP Address, username, and password.
In my case, I am using the
Putty Software
to connect to my Raspberry Pi remotely. I am also using the VNC Viewer to set up the Python programming with Thonny.
Now we need to install many modules and dependencies to the system.
Installing Python Modules & Libraries
The
Picar-X Robot
should be turned ON and Raspberry Pi should be connected to the network. Now let’s install all the Python Modules and libraries.
Lets first update the system using following commands.
sudo
apt
update
sudo
apt
upgrade
Then install the Python3 related packages.
sudo
apt
install
git
python3
pip
python3
setuptools
python3
smbus
Download & install the libraries for
Robot-Hat
cd
/
/
pi
/
git
clone
https
:
//github.com/sunfounder/robot-hat.git
cd
robot
hat
sudo
python3
setup
py
install
Running ‘
setup.py
‘ will download some necessary components. Your download may have failed due to network issues. You may need to download it again at this point. See the following interface, type ‘
Y
‘, and press Enter.
Now, download and install the ‘
vilib
‘ module.
cd
/
/
pi
/
git
clone
https
:
//github.com/sunfounder/vilib.git
cd
vilib
sudo
python3
install
py
Similarly download and install the ‘
picar-x
‘ module.
cd
/
/
pi
/
git
clone
b
v2
https
:
//github.com/sunfounder/picar-x.git
cd
picar
sudo
python3
setup
py
install
This will download a large number of files, therefore it will take time.
Once the download is complete, run the ‘
i2samp.sh
‘ script to install the components required by the i2s amplifier, otherwise the picar-x will have no sound.
cd
/
/
pi
/
picar
sudo
bash
i2samp
sh
Type ‘
y
‘ and press enter to continue running the script.
Type ‘
y
‘ and press enter to run ‘
/dev/zero
‘ in the background.
Type y and press enter to restart the Picar-X.
After restarting, the Raspberry Pi will connect to the Network and will play a sound.
If there is no sound after restarting, you may need to run the ‘
i2samp.sh
‘ script several times.
All the install
Technologies used
Hardware components
- Raspberry Pi
- HC-SR04
- Servo
- SD Card
- Servo Motor
Software & tools
- Thonny
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.