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:

Hardware

Tools

Hot Glue Gun

Soldering Iron

Prepare Frame

Decide how you will position your components.

This is important to do before you start installing components.

HC-SR04 Sensor Install the HC-SR04 sensor by press fitting it into the holes in the frame.

Position the sensor so that the pins are facing up.

Using hot glue, secure the sensor in place.

HC-SR04 Installed. Motors To install the motors, slightly lift up on one of the tabs on the frame.

Push the motor into the slot under the tab until it reaches the end.

The tabs have “teeth” on the end which should clip onto the motor housing, keeping it secure without the need for glue.

Motors installed

Dual H-Bridge Motor Driver Connect each lead from the motors into the “out” pins on the H-Bridge board Do not worry about which lead connects to each “out” pin. We can change the pins later if necessary.

Glue the H-Bridge board onto the frame. Motors installed

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.

Buck Converter Installed (Top Left), Breadboard Installed (Top Right).

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

Voltage Dividing Circuit Guide.

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.

Software Setup

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.

Mac Users

Open a terminal and run “touch /Volumes/boot/ssh” to create a file named “ssh” on the SD card.

Windows Users

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)

to (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;

country=US

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

update_config=1

network={

ssid=”NETWORK-NAME”

psk=”NETWORK-PASSWORD”

}

Mac Users

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).

Windows Users

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)

to (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 In a web browser, go to your routers admin page (http://10.0.0.1 or http://192.168.0.1 or other). Look for your Raspberry Pi and record its ip address.

Mac Users 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“. Windows Users 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: