Skip to main content
TechRadar TechRadar the technology experts
SG EditionSingapore
DK EditionDanmark FI EditionSuomi NO EditionNorge SE EditionSverige UK EditionUK IT EditionItalia NL EditionNederland BE (NL) EditionBelgië (Nederlands) FR EditionFrance DE EditionDeutschland ES EditionEspaña
US EditionUS (English) CA EditionCanada MX EditionMéxico
AU EditionAustralia NZ EditionNew Zealand
RSS
Sign in
  • View Profile
  • Sign out
  • Cyber Monday
    • Retailers
      • Cyber Monday Deals
      • Best Buy Cyber Monday Deals
      • T-Mobile Cyber Monday Deals
      • Cyber Monday Dyson Deals
    • Computing
      • Cyber Monday iPad Deals
      • Cyber Monday MacBook Deals
      • Cyber Monday MacBook Air Deals
      • Cyber Monday GPU Deals
    • TV & Audio
      • Cyber Monday Headphone Deals
      • Cyber Monday 75-inch TV Deals
      • Cyber Monday Streaming Deals
    • More Cyber Monday
      • Cyber Monday Garmin Deals
      • Cyber Monday Amazon Echo Deals
      • Cyber Monday Ring Doorbell Deals
      • Cyber Monday Blink Camera Deals
      • Cyber Monday Coupons
  • Phones
    • Popular Phone Brands
      • iPhone
      • Samsung Galaxy
      • Google Pixel
      • Nothing
      • Motorola
      • OnePlus
      • Xiaomi
      • Honor
      • Oppo
      • Huawei
    • Operating Systems
      • Android
      • iOS
    • More from Phones
      • Network Carriers
      • Phone Accessories
      • Phone Reviews
      • Phone Buying Guides
      • Phone Deals
      • Phone Coupons
      • Phone News
  • Computing
    • Laptops
      • Chromebooks
      • MacBooks
      • Windows Laptops
      • Gaming Laptops
    • PCs
      • Desktop PCs
      • Macs
      • Gaming PCs
    • Software & Security
      • Windows
      • macOS
      • Windows 10 End of Life
      • Antivirus
      • Cyber Security
    • Components
      • CPUs
      • GPUs
      • Storage
      • Nvidia
      • Intel
    • Internet
      • Websites & Apps
      • Wi-Fi & Broadband
      • Social Media
      • Wordle
    • Tablets
      • eReaders
      • iPad
    • VR & AR
    • Peripherals
      • Monitors
      • Keyboards
      • Webcams
      • Mice
    • Popular Computing Brands
      • Dell
      • HP
      • Lenovo
      • Acer
    • More from Computing
      • Computing Reviews
      • Computing Buying Guides
      • Computing Deals
      • Computing Coupons
      • Computing News
  • AI
    • AI Platforms & Assistants
    • OpenAI
    • ChatGPT
    • Gemini
    • Apple Intelligence
    • Claude
  • TVs
    • TV Insights
      • TV Reviews
      • TV Buying Guides
      • TV Deals
      • TV News
      • TVs & home theater coupons
    • More for your TV
      • Home Theatre
      • Soundbars
      • Streaming Devices
      • Projectors
      • Blu-ray
  • Streaming
    • Entertainment
    • Netflix
    • Prime Video
    • Disney+
    • Apple TV+
    • HBO Max
    • Hulu
    • Paramount+
    • How to Watch
    • Streaming coupons
  • Fitness
    • Fitness
      • Smartwatches
      • Fitness Trackers
      • Exercise Equipment
      • Fitness Headphones
      • Fitness Apps
      • Smart Rings
    • Watch Brands
      • Apple Watch
      • Fitbit
      • Garmin
      • Google Pixel Watch
      • Samsung Galaxy Watch
    • Wellbeing
      • Sleep
      • Oral Health
    • More from Fitness
      • Fitness News
      • Fitness Reviews
      • Fitness Buying Guides
      • Fitness Deals
      • Fitness coupons
  • Audio
    • Headphones
      • Earbuds & AirPods
      • Wireless Headphones
    • Speakers
      • Wireless Speakers
      • Sonos
    • Hi-Fi
      • Turntables
      • Portable Players
      • DACs
    • Audio Streaming
      • Spotify
      • Apple Music
    • More from Audio
      • Audio News
      • Audio Reviews
      • Audio Buying Guides
      • Audio Deals
      • Audio coupons
  • VPN
    • VPN Services
    • VPN Security
    • ExpressVPN
    • NordVPN
  • Cameras
    • Camera Types
      • Mirrorless
      • DSLRs
      • Compact
      • Action
      • Video
      • Drones
      • 360 Cameras
      • Dash Cams
    • Camera Brands
      • Canon
      • DJI
      • Fujifilm
      • Nikon
      • GoPro
      • Insta360
    • More from Cameras
      • Camera Accessories
      • Camera Lenses
      • Camera Reviews
      • Camera Buying Guides
      • Camera Deals
      • Camera News
      • Photography
      • Camera coupons
  • Home
    • Smart Home
      • Home Security
      • Smart Speakers
      • Smart Lights
      • Smart Scales
      • Smart Thermostats
      • Amazon Echo
    • Small Appliances
      • Air Fryers
      • Air Quality
      • Coffee Machines
      • Hair Care
      • Vacuums
      • Robot Vacuums
    • Home Brands
      • Dyson
      • Philips Hue
      • Ring
      • Shark
      • Ninja
    • More from Home
      • Home Reviews
      • Home Buying Guides
      • Home Deals
      • Home News
      • Mattress coupons
      • Home & appliances coupons
  • EVs
  • Browse
    • By Type
      • News
      • Best
      • Reviews
      • Deals
      • Versus
      • How To
      • Opinion
      • Coupons
    • Popular Brands
      • Samsung
      • Sony
      • Microsoft
      • Apple
Tech Radar Pro Tech Radar Gaming
  • Cyber Monday
    • View Cyber Monday
      • Cyber Monday Deals
      • Best Buy Cyber Monday Deals
      • T-Mobile Cyber Monday Deals
      • Cyber Monday Dyson Deals
      • Cyber Monday iPad Deals
      • Cyber Monday MacBook Deals
      • Cyber Monday MacBook Air Deals
      • Cyber Monday GPU Deals
      • Cyber Monday Headphone Deals
      • Cyber Monday 75-inch TV Deals
      • Cyber Monday Streaming Deals
      • Cyber Monday Garmin Deals
      • Cyber Monday Amazon Echo Deals
      • Cyber Monday Ring Doorbell Deals
      • Cyber Monday Blink Camera Deals
      • Cyber Monday Coupons
  • Phones
    • View Phones
      • iPhone
      • Samsung Galaxy
      • Google Pixel
      • Nothing
      • Motorola
      • OnePlus
      • Xiaomi
      • Honor
      • Oppo
      • Huawei
      • Android
      • iOS
      • Network Carriers
      • Phone Accessories
      • Phone Reviews
      • Phone Buying Guides
      • Phone Deals
      • Phone Coupons
      • Phone News
  • Computing
    • View Computing
    • Laptops
      • View Laptops
      • Chromebooks
      • MacBooks
      • Windows Laptops
      • Gaming Laptops
      • Desktop PCs
      • Macs
      • Gaming PCs
    • Software & Security
      • View Software & Security
      • Windows
      • macOS
      • Windows 10 End of Life
      • Antivirus
      • Cyber Security
    • Components
      • View Components
      • CPUs
      • GPUs
      • Storage
      • Nvidia
      • Intel
    • Internet
      • View Internet
      • Websites & Apps
      • Wi-Fi & Broadband
      • Social Media
      • Wordle
    • Tablets
      • View Tablets
      • eReaders
      • iPad
    • VR & AR
    • Peripherals
      • View Peripherals
      • Monitors
      • Keyboards
      • Webcams
      • Mice
      • Dell
      • HP
      • Lenovo
      • Acer
      • Computing Reviews
      • Computing Buying Guides
      • Computing Deals
      • Computing Coupons
      • Computing News
  • AI
    • View AI
    • AI Platforms & Assistants
    • OpenAI
    • ChatGPT
    • Gemini
    • Apple Intelligence
    • Claude
  • TVs
    • View TVs
      • TV Reviews
      • TV Buying Guides
      • TV Deals
      • TV News
      • TVs & home theater coupons
      • Home Theatre
      • Soundbars
      • Streaming Devices
      • Projectors
      • Blu-ray
  • Streaming
    • View Streaming
    • Entertainment
    • Netflix
    • Prime Video
    • Disney+
    • Apple TV+
    • HBO Max
    • Hulu
    • Paramount+
    • How to Watch
    • Streaming coupons
  • Fitness
    • View Fitness
      • Smartwatches
      • Fitness Trackers
      • Exercise Equipment
      • Fitness Headphones
      • Fitness Apps
      • Smart Rings
      • Apple Watch
      • Fitbit
      • Garmin
      • Google Pixel Watch
      • Samsung Galaxy Watch
      • Sleep
      • Oral Health
      • Fitness News
      • Fitness Reviews
      • Fitness Buying Guides
      • Fitness Deals
      • Fitness coupons
  • Audio
    • View Audio
    • Headphones
      • View Headphones
      • Earbuds & AirPods
      • Wireless Headphones
    • Speakers
      • View Speakers
      • Wireless Speakers
      • Sonos
    • Hi-Fi
      • View Hi-Fi
      • Turntables
      • Portable Players
      • DACs
    • Audio Streaming
      • View Audio Streaming
      • Spotify
      • Apple Music
      • Audio News
      • Audio Reviews
      • Audio Buying Guides
      • Audio Deals
      • Audio coupons
  • VPN
    • View VPN
    • VPN Services
    • VPN Security
    • ExpressVPN
    • NordVPN
  • Cameras
    • View Cameras
      • Mirrorless
      • DSLRs
      • Compact
      • Action
      • Video
      • Drones
      • 360 Cameras
      • Dash Cams
      • Canon
      • DJI
      • Fujifilm
      • Nikon
      • GoPro
      • Insta360
      • Camera Accessories
      • Camera Lenses
      • Camera Reviews
      • Camera Buying Guides
      • Camera Deals
      • Camera News
      • Photography
      • Camera coupons
  • Home
    • View Home
    • Smart Home
      • View Smart Home
      • Home Security
      • Smart Speakers
      • Smart Lights
      • Smart Scales
      • Smart Thermostats
      • Amazon Echo
    • Small Appliances
      • View Small Appliances
      • Air Fryers
      • Air Quality
      • Coffee Machines
      • Hair Care
      • Vacuums
      • Robot Vacuums
      • Dyson
      • Philips Hue
      • Ring
      • Shark
      • Ninja
      • Home Reviews
      • Home Buying Guides
      • Home Deals
      • Home News
      • Mattress coupons
      • Home & appliances coupons
  • EVs
  • Browse
    • View Browse
      • News
      • Best
      • Reviews
      • Deals
      • Versus
      • How To
      • Opinion
      • Coupons
      • Samsung
      • Sony
      • Microsoft
      • Apple
Tech Radar Pro Tech Radar Gaming
Don't miss these
Commodore 64 Ultimate
Computing The Commodore 64 is back on the production line for the first time in 30 years – and I want it, even if it makes zero sense
Original PRUSA CORE One
Pro Best 3D printer of 2025
Roborock Qrevo Master robot vacuum
Robot Vacuums The best robot vacuum 2025
The DJI Mini 4K drone in flight with tree backdrop, alongside DJI Mavic 4 Pro in flight with blue sky backdrop
Drones The best drone 2025 based on in-depth testing
Close up of the Linux penguin.
Software & Services Best Linux distro of 2025
Apple Pie AI
AI Platforms & Assistants I asked ChatGPT and Gemini to improve my mom's Apple Pie recipe, and the results were unforgettably bad
Disney Imagineering Olaf next-gen robot
Entertainment Disney's new Olaf robot is so real, it'll give you chills
Photo diptych with DJI Mini 5 Pro in the air on the left, and the DJI Neo 2 in person's hand on the right
Drones The best beginner drones for 2025
Giftster
Websites & Apps I can feel the gift list stress already, but this smart app could calm me down
Unitree G1 flies Antigravity A1
AI Platforms & Assistants Drone maker lets robot fly drone to prove it's easy to use and scare the heck out of us
Lego sets
Seasonal Sales I’m Lego obsessed – here are the 58 Best Black Friday Lego deals worth shopping
Ruko F11 Pro drone and accessories on a blue background alongside techradar black friday deals text overlay
Drones This beginner fly drone by Ruko plummets to $220, and it has DJI-beating features
DJI Neo 2
Drones DJI Neo 2 review: takes selfie drones to new heights
Lego Star Wars Black Friday Deals at Walmart
Seasonal Sales The 11 best Black Friday Lego Star Wars deals to shop right now
Putapre, a retro tape reader
Pro Retro computer boffin creates an all-new perforated tape reader - just don't expect high data reading speeds
Trending
  • Best laptop
  • Best VPN
  • Best web hosting
  • Windows 10 end of life
  • NYT Wordle today
  • ChatGPT
  1. Computing
  2. Desktop PCs
  3. Raspberry Pi

How to build your own R2-D2 with the Raspberry Pi Zero

How Tos
By Les Pounder published 11 December 2017

Hack a toy

When you purchase through links on our site, we may earn an affiliate commission. Here’s how it works.

Build your own R2-D2 using Raspberry Pi

Build your own R2-D2 using Raspberry Pi

What Star Wars fan hasn't dreamed of owning their own droid? The droids C-3PO and R2-D2 serve as the narrators to an epic story encompassing good versus evil.

With the upcoming release of the latest film in the series, The Last Jedi, now is an excellent time to try your hand at building your very own R2-D2.

C-3PO is a protocol droid who lives to serve his master, while R2-D2 was first seen (chronologically) in Episode 1: The Phantom Menace, and saved Queen Amidala and her party as they left the planet of Naboo. R2-D2 is an Astromech droid, a robotic engineer that can fix any problem.

In this tutorial we'll construct our own R2-D2 robot by hacking a store-bought toy with the latest Raspberry Pi, the Raspberry Pi Zero.

The Raspberry Pi Zero is an ultra-low-cost Raspberry Pi, and retailing at $5 (£4, around AU$7) this board provides a full computer experience for very little money. Coming with 512MB of RAM, 1GHz ARM CPU and able to output 1080p video, it's been flying off the shelves, and the Raspberry Pi Foundation is working to restock.

We'll also be using the latest Explorer pHAT board from Pimoroni. This board is a cheap and easy to use motor controller and experiment board, and will provide the functionality for our R2 unit.

For this project you will need:

  • A Raspberry Pi Zero, or another Raspberry Pi (A+,B+ or Pi 2)
  • The latest version of the Raspbian operating system
  • Wi-Fi connection for your Raspberry Pi
  • 2x Micro gear metal motors
  • Wheels for R2
  • Explorer pHAT board
  • An LED
  • A 220 Ohm resistor (RED-RED-BROWN)
  • Male-to-female jumper cables
  • Male-to-males jumper cables
  • 2x Terminal block with screw terminals
  • Hot glue gun
  • Soldering Equipment

The majority of these components can be found at Pimoroni and The Pi Hut.

You can also download all of the code for this project.

Don't fancy building your own R2-D2? You can cheat and buy your own robotic R2-D2 with the Sphero R2-D2.

Page 1 of 11
Page 1 of 11
1. Solder the GPIO

1. Solder the GPIO

Before we can use the Raspberry Pi Zero, we will need to solder the GPIO, a series of 40 pins, onto the board.

These pins enable our Explorer pHAT add-on board to interact with the Raspberry Pi. For the best results use a blob of modelling clay to support the board while you solder. If you can't solder, ask a local hackspace, DIY expert or friends for help. You will also need to solder the header pins for the Explorer pHAT board.

If you're using another type of Raspberry Pi then you can skip this step, as the GPIO comes pre-soldered.

Page 2 of 11
Page 2 of 11
2. Hack the R2-D2 toy

2. Hack the R2-D2 toy

We chose a small R2-D2 toy costing around £20 (around $30, AU$42). We started by removing all of the internal components, to see what room we had to hack. It was quite tight even for the Raspberry Pi Zero, so we chose to house the major components on the rear of R2-D2.

We removed R2-D2's legs and measured the size of our motors on the feet. Using a Dremel tool we carefully cut and shaped a space for the motors on each foot.

How to build your own R2-D2 with the Raspberry Pi Zero

Before attaching the motors we soldered wires to the terminals for later use, so give yourself plenty of spare wire, and attach the wires for each motor to the Motor 1 and 2 header on Explorer pHAT. Use hot glue to secure the motors in place on the feet.

Page 3 of 11
Page 3 of 11
3. Let there be LED

3. Let there be LED

For added authenticity we drilled a hole in R2-D2's red eye socket, and replaced the plastic with an actual working red LED.

Inside R2-D2's head we used a terminal block, commonly used in electrics to secure wires without soldering, and secured the legs of the LED into each hole.

How to build your own R2-D2 with the Raspberry Pi Zero

The long leg of the LED will receive 5V power from the Explorer pHAT via a 220-ohm resistor screwed into the other end of the block and linked to the Explorer pHat via a female to male jumper cable. The short leg will connect to Output 1 of the Explorer pHAT.

Page 4 of 11
Page 4 of 11
4. Power R2-D2 up

4. Power R2-D2 up

Attach the Explorer pHAT to the Raspberry Pi, then connect your peripherals before powering up the Raspberry Pi.

Once the Raspberry Pi has booted you'll need to have an Internet connection before proceeding. Open a terminal (its icon is a dark screen in the top left of your desktop), and type the following to install the Explorer pHAT software:

curl get.pimoroni.com/i2c | bash

You'll be asked a series of questions, to which you can answer yes, as it's quite safe in this instance. After a few moments the software will be installed, and to ensure that it has been done correctly now is a good time to reboot your Raspberry Pi. When done, return to the desktop.

Page 5 of 11
Page 5 of 11
5. Coding R2-D2

5. Coding R2-D2

To code our R2 unit we'll be using Python, a really easy to use language that is well suited to the Pi, and which the majority of the Raspberry Pi community uses as their primary language. To code in Python we need to open the Python3 application, which you can find in the Programming menu.

When Python3 is open, click on File > New Window to open a new blank document. Now save the project as R2P10.py before proceeding. Remember to regularly save your work – this is a good habit to get into, as it will limit any accidental deletions.

Page 6 of 11
Page 6 of 11
6. Import code

6. Import code

Our first three lines of Python code are imports – these bring in external libraries of code for our project to use.

import explorerhat
from time import sleep
from random import randint

Firstly we import the library for Explorer pHAT – this will enable our project to interface and use the board.

The next two imports are used to import one aspect of each library. From the time library we import the sleep function, used to control the pace of our code. From random we import a random integer generator, used later in the project.

Page 7 of 11
Page 7 of 11
7. More coding

7. More coding

We now move to the main body of code (shown above).

Here we create a method to test our code, and inside it we use a loop that will run forever, while True; this loop will run the code to set output 1 of our Explorer pHAT so it blinks every half a second. We now create a variable, a container that can store any type of data – in this case we're using it to store a random number, an integer, between 1 and 5.

The indentation of code is important, and Python 3 will help you as you type.

Page 8 of 11
Page 8 of 11
8. Moving R2-D2

8. Moving R2-D2

For our next section of code, we will turn on the motors and control R2-D2.

We start by turning both of our motors on and forward at 20% power, a nice glide for R2-D2 to move along on. If your motor is running in the wrong direction, swap the wires for that motor so that they're reversed in the Explorer pHAT.

With the motors on we use a delay, sleep, to prevent the motors stopping. We use the random number stored in the variable, duration, to control how long R2 will run for. Next we run one motor backwards to enable R2 to turn on the spot; this is also controlled for a set duration.

Page 9 of 11
Page 9 of 11
9. Testing your code

9. Testing your code

This next section of code exists outside of the while True loop.

We started the code by using a test, try, now we need to add an exception – in this case when we press CTRL+C to stop the code running. When this occurs we tell the motors to turn stop, and for the output to turn off, stopping R2-D2's eye blinking.

Save your code and prepare to test your R2 unit! For the best results hold on to the R2-D2 unit, otherwise it will run away.

Page 10 of 11
Page 10 of 11
10. Control R2-D2

10. Control R2-D2

With our code complete you can now run the code by clicking on Run > Run Module in the menu. R2-D2 should move forward for a few seconds, then turn left.

This code will then repeat until you press CTRL+C. For a truly portable solution you can use a USB battery pack, such as those used to charge your mobile devices, to power the Raspberry Pi. You can also control R2 over a Wi-Fi connection using technologies such as SSH and VNC.

And there you have it – your very own R2-D2 unit, ready to respond to your commands!

  • Find out what else you can do with the tiny PC with our collection of Raspberry Pi Projects
Page 11 of 11
Page 11 of 11
TOPICS
Star Wars
Les Pounder
Read more
Lego UCS Death Star
Inside Lego’s redesign of the Death Star – its most ambitious Star Wars set ever
 
 
Miniature Legacy Lightsaber Hilts Countdown Calendar - Star Wars 1
This might be the coolest Star Wars holiday countdown yet, and it's exclusive to the Disney Store
 
 
Google AI Figurines
I turned myself into a 3D figurine with Google's Nano Banana - here's how you can hop on the latest AI image trend
 
 
Disney Imagineering Olaf next-gen robot
Disney's new Olaf robot is so real, it'll give you chills
 
 
Putapre, a retro tape reader
Retro computer boffin creates an all-new perforated tape reader - just don't expect high data reading speeds
 
 
Hear Your Wi-Fi
The worst part of dial-up internet is back - Raspberry Pi modder lets you "hear" your Wi-Fi
 
 
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
LONDON, ENGLAND - MARCH 31: Logan Paul and AJ Styles in ring during Monday Night RAW at The O2 Arena on March 31, 2025 in London, England.
WWE Survivor Series: WarGames - Stream it *FREE* with this trial offer
 
 
ChatGPT Agent
ChatGPT’s Agent feature lets you assign tasks and walk away – here’s how
 
 
Bangladesh's Ripon Mondol (L) celebrates with teammates after the dismissal of India's Yashasvi Jaiswal ahead of the 2025 Asia Cup Rising Stars final featuring Bangladesh vs Pakistan in Doha on Nov, 23 2025. (Photo by Ishara S. KODIKARA / AFP) (Photo by ISHARA S. KODIKARA/AFP via Getty Images)
Bangladesh vs Pakistan live streams *FREE*: Watch Asia Cup Rising Stars final from anywhere
 
 
AI Robots
Creating images with ChatGPT is fun and these tips will make them better
 
 
Carlos Alcaraz in action for Spain at the Davis Cup.
How to watch Davis Cup Finals 2025: live stream tennis online, TV channel, order of play
 
 
Headshots of website builder experts with a purple spiral background and white text over the top.
Optimizing for online sales: Your insider guide to Black Friday success
 
 
LATEST ARTICLES
  1. 1
    The Abandons review: New Netflix western is no Yellowstone, but Gillian Anderson shines
  2. 2
    I installed the TerraMaster D4‑320U into my studio, and it proved to be a fast way to boost on-site data storage
  3. 3
    Sorry Apple, but I don’t think iOS 26 is fit for purpose
  4. 4
    Google’s Antigravity AI deleted a developer’s drive and then apologized
  5. 5
    How to watch Australia vs England: live stream 2nd Ashes Test for *FREE* from anywhere in the world

TechRadar is part of Future US Inc, an international media group and leading digital publisher. Visit our corporate site.

Add as a preferred source on Google
  • About Us
  • Contact Future's experts
  • Contact Us
  • Terms and conditions
  • Privacy policy
  • Cookies policy
  • Advertise with us
  • Web notifications
  • Accessibility Statement
  • Careers

© Future US, Inc. Full 7th Floor, 130 West 42nd Street, New York, NY 10036.

Please login or signup to comment

Please wait...