An amazing first project for the Raspberry Pi is a three-wheeled robot car. It is simple to make but you can expand it to do anything you want it to. First, I’ll show you how to build the chassis and set up the Raspberry Pi. Next, there are different programs and sometimes extra components that I call modules. You can use them to make robots based on the base design. With small changes, they can do anything from follow a simple preset program to drive themselves!
What you Need
- Robot Chassis with Motors and Wheels
- Power Bank
- Raspberry Pi 3 or 4 computer
- 16 GB or more SD card (only use an SD card that someone else has already tried, some of them don’t work.)
- DuPont Wires
- Mini Breadboard
- L293D Chip
- Micro USB to USB cable for the motors, and another micro USB cable if you are using a Pi 3, or a USB-C to USB cable if you have a Pi 4.
- Extra parts if needed for modules
Step 1: Chassis
First of all, you need to make a chassis. Anything from strong cardboard from a packing box to a metal pre-built chassis will work. The requirements are a piece of material that is big enough and strong enough to hold everything. It also can’t be too heavy for the motors.
Step 2: Power source
For a Raspberry Pi robot, you need to buy a power bank that is capable of putting out 3A current. You can find the power bank’s current in the specs. It also needs 2 USB ports, one for the Raspberry Pi’s power, and another for the motors. Mount the power bank onto your chassis, and charge it up.
Step 3: Raspberry Pi Setup
For this project, the controller is a Raspberry Pi and a phone or a Chromebook. To set up the Raspberry Pi, first, install the Raspberry Pi Imager on your computer. You can do that by downloading and running the installer file. Be sure to get the right file for your operating system (Windows, macOS, etc). Then, open the Imager.
Select the Choose OS menu, and click/tap the Raspberry Pi OS (Other). Next, Click the Raspberry Pi OS Lite button. After that, select the Choose Storage button. Insert the SD card into your computer, and select it. Hit Ctrl+Shift+X, which brings up an options menu. Select the options to enable Wi-Fi, enable SSH, and set the password. Save your settings, exit the options menu, and click the Start Flashing button. Once that’s done, put the SD card into the Raspberry Pi’s socket. For more information on setting up a Raspberry Pi, check out my Raspberry Pi Quickstart Guide.
Connecting the Motors to the Raspberry Pi
You can’t connect motors to the Raspberry Pi. They use so much current that they would break it. To fix this problem, you need an L293D motor driver circuit. It allows the Pi to control the motors but powers them with an external power supply (the power bank). Take out your mini breadboard, DuPont wires, micro USB to USB cable, and L293D chip. Follow the circuit diagram below, being sure to orient the chip the right way. You can find which direction it goes by looking at the indent on the chip. Also, connect the wires to the Raspberry Pi as indicated.
Next, mount the motors to the chassis with hot glue or screws. Also find a place for the Pi, breadboard, and power bank. Mount it with hot glue, tape, string, or almost anything else. Make sure that the Raspberry Pi has a non-conductive base under it. That will keep it from shorting out, such as paper or cardboard. Lastly, connect the wheels to the motors with the included screws.
How to Add Code to the Raspberry Pi
To code the Raspberry Pi, you need a computer with Chrome installed. You need an Internet connection too. The first thing you need to do is install the Secure Shell Chrome extension. Click here to go to the Secure Shell page on the Chrome Web Store. Then, select the “Add to Chrome” button. After the extension installs, click the icon in the toolbar.
Select “Connection Dialog”. An SSH window will pop up.
Type in pi@raspberrypi in the username/hostname box. Also, as in the screenshot, type pi in the username field, and raspberrypi in the hostname field. Hit Enter to connect, type “yes” into the dialog box, and then hit enter. Fill in the password you set earlier in the Raspberry Pi Imager, and hit Enter again.
It will show you a terminal. You can type commands into it to do all kinds of things. First, type in:
sudo nano robot.py
A very basic text editor will come up. You can’t use the mouse or touchpad on it, so you can only navigate with the arrow keys. Next, decide which kind of robot you want to make.
- Simple Raspberry Pi robot that follows preset paths
- Android smartphone, tablet, or Chromebook controlled robot
- Automatically navigating robot with a distance sensor
- Robot controlled by a TV remote
- Android smartphone tablet/Chromebook controlled talking robot
Module 1: Simple Raspberry Pi Robot that follows preset paths
The first module is a simple program to make your robot follow a preset path. It asks you for a command and then stores it in a list. You can type in forward, backward, left, or right. It will do each thing for 2 seconds. If you type in “go” when it asks you for a command, the robot runs through the list and does each thing you typed in. You don’t need any extra components to do this. Download the code below and open it in your favorite text editor. Highlight the whole thing with Ctrl+A and then hit Ctrl+C to copy it. Inside the Secure Shell window, right-click to paste the code into it. Next, Hit Ctrl+S and then Ctrl+X to save the code onto the Pi and exit the text editor.
To try out your code, type in the below command, and then hit enter. You will be prompted to enter a number. The number will be the number of seconds it does each thing for (forward, backward, etc.). It will ask you what command you want to add. Type in “forward”, “backward”, “left”, or “right” as many times as you want to create your program. Also, you can type “program”, and it will show you your list of commands. Once you’re done, type “go”. The robot will start following your program.
sudo python robot.py
Module 2: Android smartphone, tablet, or Chromebook controlled robot
Another cool robot you can make is a robot controlled by a smartphone. It uses an app called Rootsaid WiFi Command Center. This app sends UDP packets over the Internet, which is a little bit of text that the Raspberry Pi can receive. To make this robot, download the code below.
Next, open the code in your computer’s text editor. Hit Ctrl+A to select all the code, and hit Ctrl+C to copy it. Click the Secure Shell window and right-click inside of it to paste the code onto your Pi. Still inside the Secure Shell window, hit Ctrl+C and then Ctrl+X to exit and save the text editor. Type in the following command to get your IP address, and make a note of it.
Next, type in this command to start the program:
sudo python robot.py
Download the Rootsaid WiFi Command Center app from the Play Store onto your phone, Chromebook, or tablet, and open it. In the Setup tab of the app, type in the IP address of your Pi, and in the Port field, type in 5050. Tap the link icon. Go to the Robot Controller tab. To drive the robot, tap the forward, backward, left, and right icons. This app could potentially be used for tons of different things, such as home automation.
Module 3: Raspberry Pi robot controlled by a phone over Bluetooth with the Blue Dot app
Thanks to Blue Dot by Martin O’Hanlon for this code and the companion app! With this module, you can use an app with a simple blue dot on the screen that connects to your robot over Bluetooth. It detects where your finger is on the dot and goes in that direction. The speed of the robot is decided by where your finger is, too. The closer your finger is to the edge, the faster your robot will go.
Pairing with a phone
To connect your phone/tablet/Chromebook to your Pi, go into the Secure Shell window on your computer. Exit nano, type in bluetoothctl, and press enter. At the [bluetooth]# prompt type in the following commands, pressing enter after each one.
- discoverable on
- pairable on
- agent on
- scan on
Turn on Bluetooth on your phone, and wait for a message that says it was discovered:
[NEW] Device 12:23:34:45:56:67 devicename
On your phone, select your Pi from the Bluetooth devices list, and hit Pair. The Pi will ask you several things, type “yes” then hit enter for all of them. In the Secure Shell window, type exit in the Bluetooth prompt.
Type in “sudo apt install python3 python3-pip”, and then press enter. After that finishes, type in “sudo pip3 install bluedot”, then hit enter. Then, type “sudo nano bot.py”. Download the dotbot.txt file below, and open it on your computer. Hit Ctrl+A to select all the code, and the Ctrl+C to copy it. Go into the Secure Shell window and right-click to paste it onto your Pi. Hit Ctrl+S to save, and then Ctrl+X to exit nano. Type “sudo python3 bot.py” to run your code.
On your phone, go to the Play Store and download the Blue Dot app. Open it, and select your Pi from the list of devices. Then, use the blue dot to drive your Raspberry Pi robot!
Module 4: Talking robot
A talking robot is one of the easiest modules to use. To do it, first exit nano. Then, type in “sudo apt-get install espeak”. That will install the espeak program. To control it with Python, type “sudo nano talking.py”. Download the following code and copy it. Paste it into Nano.
Hit Ctrl+S and Ctrl+X to save your code and exit nano. Type “sudo python talking.py”. It will ask you what it should say, and then say it. After that, the program will exit.
If you enjoyed this post, please comment below. You could also check out our article on the Best Raspberry Pi Operating Systems for Everyday Use.