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
Latest in Raspberry Pi
white keyboard PC with mouse and book
The Raspberry Pi 500 is a state-of-the-art keyboard PC...just like the Tandy 1000 in the 1980s
Raspberry Pi strapped to a satellite takes stunning picture of Earth
Kali Linux on Pi 4
Raspberry Pi 4 gets Kali Linux, a distro aimed at ethical hackers
Worried about Alexa spying on you? This Raspberry Pi smart speaker for kids puts privacy first
How to install Ubuntu on the Raspberry Pi
New Raspberry Pi 3 Model A+ is somehow even smaller and cheaper
Latest in How Tos
This City Is Ours
How to watch This City Is Ours online – stream Sean Bean crime drama from anywhere
Canada's Val Sweeting competes during the LGT World Womens Curling Championship match for third place ahead of Canada's showing at the Women's Curling World Championships 2025
Women's Curling World Championships live stream: how to watch Uijeongbu 2025 online, schedule, streaming guide
Thomas Tuchel, Head Coach of England, reacts during a training session at St George's Park on March 17, 2025 in Burton upon Trent, England.
England vs Albania live stream: How to watch 2026 World Cup qualifier online and from anywhere today, team news
Smartphone with new logo X twitter app background. Application twitter old blue bird change X black and white new.
How to delete all your tweets on X
ChatGPT Voice mode
How to add ChatGPT or Gemini voice mode to your iPhone Action button (while you wait for Siri's big upgrade)
McLaren’s Oscar Piastri driving on a straight in qualifying for the Chinese Grand Prix 2025
How to watch Chinese Grand Prix 2025: TV & live streams, schedule, start time, what channel is it on? Piastri on pole