This robot build is meant to be relatively cheap and easy. It should provide a good first project for people looking to learn to code, specifically in the Python programming language. Here is what you will need to get started:
- 1 3D Printed Frame
- 1 Raspberry Pi
- 1 Dual H-Bridge Motor Driver
- 1 Buck Converter
- 2 3V-6V DC Motors
- 1 HC-SR04 Ultrasonic Sensor
- 1 2S Lipo Battery
- 1 Mini Breadboard or PCB Board
- 1 1k resistor
- 1 2k resistor
- F2F and M2F Jumper Wires
- Hot Glue Gun
- Soldering Iron
- Decide how you will position your components.
- This is important to do before you start installing components.
Buck Converter & Bread Board
- Solder the proper leads onto your Buck Converter.
- The leads connected to the in+ and in- spots should have a connector that is compatible with that of the lipo battery.
- The leads coming off of the out+ and out- can be normal jumper wires.
- The out+ will power the motors, connect it to the +12V terminal on the H-bridge.
- The out- will need to have 2 leads coming off of it.
- One will be connected to ground on the H-Bridge.
- The other lead will be connected to a ground pin on the Raspberry Pi. This lead acts as a common ground.
- The breadboard will be used to create a voltage dividing circuit. This will be covered more in depth in the next step.
Wiring the Dual H-Bridge
IN1 -> GPIO 2
IN2 -> GPIO 3
IN3 -> GPIO 4
IN4 -> GPIO 17
Wiring the Ultrasonic Sensor
VCC -> 5V GPIO
TRIG -> GPIO 27
ECHO -> Voltage Dividing Circuit -> GPIO 22
Why use a voltage dividing circuit?
The echo pin on the HC-SR04 sensor outputs 5 volts. The GPIO pins on the Pi are only rated for 3.3 volts. Giving a GPIO pin 5 volts may cause damage to the Pi. A voltage dividing circuit will convert the 5V signal from the HC-SR04 into 3.3V, safe for the Raspberry Pi.
Here is what you need to do to get the necessary software up and running.
- Install Raspbian onto a micro SD.
- Enable SSH and setup WiFi configuration.
- SSH into the Raspberry Pi.
- Download the code from GitHub.
- Download any missing dependencies.
- Bring your robot to life.
1. Installing Raspbian
- Download Raspbian, I will be using Raspbian Lite.
To burn an image to the SD card you can use Etcher.
- Head over to https://etcher.io.
- Download the version for your operating system.
- Run the installer.
Using Etcher is very intuitive and straight forward.
- Select image – Browse to the Raspbian image that you downloaded.
- Select disk – Select the SD card for your Raspberry Pi.
- Click “Flash!” Then wait for the image to be written.
- Done! Raspbian is now installed on the SD card.
2. Enable SSH and configure WiFi
For security reasons, SSH is disabled by default. To enable SSH you will need to keep the Raspberry Pi’s micro SD card inserted into your computer after Raspbian has been copied onto it.
- Open a terminal and run “touch /Volumes/boot/ssh” to create a file named “ssh” on the SD card.
- Using Notepad, open a new file, enter one empty space and nothing more
- Click File / Save As …
- Be sure to set Save As type to All Files (so the file is not saved with a .txt extension)
- Name the file ssh and save it onto the SD card.
Configuring the WiFi prior to boot is very useful for a headless Raspberry Pi. Doing so removes the need for an extra keyboard, mouse, monitor, and HDMI cable.
To setup the WiFi configuration file, you will need to:
- Create the configuration file on the SD card.
- Enter the following text into the configuration file;
- Open a terminal and run “touch /Volumes/boot/wpa_supplicant.conf” to create the WiFi configuration file on the SD card.
- Edit the wpa_supplicant.conf file and paste the text from above into the file. Make sure to enter your WiFi login details in the correct field (NETWORK-NAME).
- Using Notepad, paste in the text from above. Make sure to enter your WiFi login details in the correct field (NETWORK-NAME).
- Click File / Save As …
- Be sure to set Save as type to All Files (so the file is not saved with a .txt extension)
- Save the file as “wpa_supplicant.conf“.
3. SSH into the Raspberry Pi
- Eject SD card from your computer and insert it into the Raspberry Pi.
- Power on the Raspberry Pi and wait for it to boot up (> 90 seconds)
- Find ip address of the Raspberry Pi
- Open a terminal and run “ssh pi@ip_address_of_pi” replacing ip_address_of_pi with the actual ip address of your Raspberry Pi.
- A prompt may appear asking if you would like to continue connecting despite the lack of authenticity. Enter “yes“.
- Then you will be prompted for the password. The default password is “raspberry“.
- Head over to https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html and download the version for your operating system.
- In PuTTY, create a new configuration for your Raspberry Pi.
- Default username: pi
- Default password: raspberry
- Host name: ip address for your Raspberry Pi
- Port: 22
- SSH into your Raspberry Pi.
After SSH-ing into your raspberry pi you will want to update the system by running:
- sudo apt-get update
- sudo apt-get upgrade
You should then improve the security of your Raspberry Pi by following this guide.
4. Download the code from GitHub
While connected to your Raspberry Pi over SSH:
- Download git and pip3 by running “sudo apt-get install git python3-pip”.
- Download the code from my Github by running “git clone https://github.com/MiguelAgueda/ARCRobot/”
5. Download any missing dependencies
My code relies on the RPi.GPIO library to work correctly.
- Download RPi.GPIO using pip3 by running “pip3 install RPi.GPIO”
6. Bring your robot to life
- Change into the ARCRobot-1 directory inside of the arcrobot directory by running “cd arcrobot/ARCRobot-1/”
- Start the robot’s autonomous mode by running “python3 go_auto.py“
That’s it! Whenever you reboot your Raspberry Pi, all you need to do is re-do step 6 to get your robot up and running. Thank you for following my guide! Please leave feedback regarding anything that was unclear so that I can help clarify.