How to build a robot with Raspberry Pi

How to build a robot with Raspberry Pi

Robotics is an exciting way to introduce people to programming but it can also be a little difficult sometimes for newcomers to get to grips with as well as being expensive.

Enabling anyone to create an easy to build and cost-effective robot is a significant step in their learning. So in this tutorial we shall build our own robot and create a Python 3 library that enables anyone to control it.

For this project you will need: any model of Raspberry Pi; Raspbian, a Wi-Fi dongle and have the Raspberry Pi connected to your home router; a USB battery pack, a robot chassis kit, an L298N motor controller; four AA batteries and some Blu-tack.

Building a robot chassis is a great activity and the kit (mentioned above) comes with everything that you need to get started. You will need to solder the red and black wires to the motor terminals, if you can't solder then now is a great time to learn from a friend.

Soldering

In this project we bought a robot chassis kit from eBay that included two DC motors. These motors come assembled but require soldering two wires to the terminals for power. Soldering is an essential maker skill and it is really easy to learn, though adult supervision is essential for our younger would-be solders out there.

There are many YouTube tutorial videos, but the best is from Carrie Anne Philbin (below).

Soldering irons sets can be bought for around £10, but a good example is the Antex XS25 for around £25, which is a great starter to intermediate soldering iron.

Soldering should be undertaken in a spacious, well-ventilated room with a clear workspace. Soldering is great fun and your local hackspace/LUG can help you to learn in a safe manner.

How to build a robot with Raspberry Pi

The L298N board is packed full of components. The screw terminals enable connections between the batteries, Raspberry Pi and motors

With the chassis built, we now focus on the motor controller which is an L298N H bridge controller. An H bridge enables a motor to go forwards and backwards. Our L298N has two outputs for our motors, the left side is served by OUT1 and 2, the right by OUT3 and 4.

Connect the wires from your motors to these terminals and ensure they are secure. Our AA battery pack connects to +12V and GND terminal.

We also need to connect one of the GND from our Raspberry Pi to the L298N GND terminal. On the L298N we can see four pins marked IN1 to IN4. These are inputs that we use to connect the L298N to our Raspberry Pi GPIO (General Purpose Input Output) pins.

By turning a GPIO pin on or off we can trigger the input pins accordingly and control the motor direction. We connected our inputs to the following GPIO pins: IN1 to 17, IN2 to 22, IN3 to 18 and IN4 to 23. We used the Broadcom pin mapping, a standard set by the Raspberry Pi Foundation.

Check out this great reference for the GPIO which explains Broadcom pin mapping.

TOPICS