A robot rover using a PiZero – Part 1

PiWars is an event like Robot Wars, which you may have seen on TV, but without the destruction.  If you think that sounds boring you need to find out about the great courses the PiWars team put the robots through.  I particularly enjoyed the ‘balloon popping’ one.


After visiting PiWars, I decided I had to have a go at making a robot rover myself.  Not being that clever and allergic to soldering, I decided to buy a kit.  (Well not literally allergic but absolutely useless at it!)

Here are my costings:

This assumes you’ve got some sort of Raspberry Pi already. So you’ve got a power supply, keyboard, mouse, screen and powered USB hub – all with cables.

What you need                                               £

Pi Zero                                                                (4.80)

SD card with NOOBS                                       6.50

Adapter Kit                                                        4.20                     (Can be used for other projects)

This is:   {HDMI -> mini HDMI adapter

               {Female USB A -> micro-B USB cable

Hammer heading kit with Male Header    (6.00)  (Can be used again, new male header £2)

or buy a Pi Zero from  Pi-Supply at            10.00 with a male header fitted already

Robot CamJam EduKit #3                              18.00

Old Tupperware box                                        0.00                     (or the CamJam box or similar)

Total                   £38.70

I am pleased to say that the wheels turned when I tried it, so I must have done all the electronics correctly, and Michael & Tim’s instructions are excellent!  It’s the first time I’ve understood everything in a project’s materials.


Here’s the Python code I used (The indenting hasn’t come out here):

import RPi.GPIO as GPIO

import time

# Set the GPIO modes



# Set variables for GPIO pins

pinMotorAForwards = 9

pinMotorABackwards = 10

pinMotorBForwards = 7

pinMotorBBackwards = 8

# Set the GPIO Pin mode

GPIO.setup(pinMotorAForwards, GPIO.OUT)

GPIO.setup(pinMotorABackwards, GPIO.OUT)

GPIO.setup(pinMotorBForwards, GPIO.OUT)

GPIO.setup(pinMotorBBackwards, GPIO.OUT)

# Turn all motors off

def StopMotors():

GPIO.output(pinMotorAForwards, 0)

GPIO.output(pinMotorABackwards, 0)

GPIO.output(pinMotorBForwards, 0)

GPIO.output(pinMotorBBackwards, 0)

# Turn both motors forwards

def Forwards():

GPIO.output(pinMotorAForwards, 1)

GPIO.output(pinMotorABackwards, 0)

GPIO.output(pinMotorBForwards, 1)

GPIO.output(pinMotorBBackwards, 0)

# Turn both motors backwards

def Backwards():

GPIO.output(pinMotorAForwards, 0)

GPIO.output(pinMotorABackwards, 1)

GPIO.output(pinMotorBForwards, 0)

GPIO.output(pinMotorBBackwards, 1)







The only bit I was stuck on was finding instructions to start the code working automatically, once I’d separated the PiZero from it’s cables and switched on the battery box.  I expect you have to use some sudo commands in the LX Terminal.  Apparently I need to use this post: Raspberry Pi’s Linux Documentation which explains the correct commands to start up the PiZero and run my python code automatically.

Well, I feel I’ve made great progress today – so separating PiZero from it’s cables, and getting it to start the code (which moves the wheels) automatically, will be in Part 2.

Happy R Pi tinkering!


PS You can now buy PiZeros, with the male header already soldered on, from Pi-Supply .


One thought on “A robot rover using a PiZero – Part 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s