This is an archived resource. The repo will remain available but the resource will no longer be maintained or updated. Some or all parts of the resource may no longer work. To see our latest resources, please visit raspberrypi.org.
Build and control a Raspberry Pi-powered robot with a Nintendo Wiimote.
It's always good to break down projects into chunks, as it makes it much easier to troubleshoot. If you do this project all at once and it doesn't work, how do you know if it's the motor board, the motors, the Bluetooth connection or your program at fault? The steps are:
- Set up and test the motor board and motors
- Set up and test the Bluetooth connection
- Set up and test the Wiimote
- Write the final program
- Build your robot's body
- Serve a nice cup of tea to your mum.
Put the board on the Raspberry Pi GPIO pins. It should look like this:
Connect one motor to the blue connector marked J3/M1, using wires stripped at each end or male-male header cables. Connect the other motor to J2/M2. It does not matter which way round you connect each individual motor at this point (if a motor turns the wrong way then just swap the wires around) but you should have something like this:
Tape the connections between the motor wires and the headers, to stop them coming loose.
Finally, connect the battery pack to the motor board as shown above. Here's what you should have at this point:
You now have a battery pack connected to the robot's motors via the motor control board. We will use the Raspberry Pi to control how and when the motors receive power.
The Ryanteck board is controlled using pins 17, 18, 22 and 23 of Raspberry Pi GPIO . If you set pin 17 high, motor one goes clockwise, whereas pin 18 high turns it anticlockwise. Pins 22 and 23 control motor 2.
Let's write a small Python script to test that everything's working.
At the command line type nano test_motors.py. Type in the following program:
import RPi.GPIO as io
import time
io.setmode(io.BCM)
pins = [17, 18, 22, 23]
for pin in pins:
io.setup(pin, io.output)
#test motors by spinning each one way then the other with 0.5 sec delay
for pin in pins:
print ('Testing pin ' + str(pin))
io.output(pin, 1)
time.sleep(0.5)
io.output(pin, 0)Press CTRL-o and then Enter to save
Press CTRL-x to exit to the command line
Now run the test program: sudo python test_motors.py.
If the test does not run as expected, check all connections and batteries and try again.
- Plug the Bluetooth dongle into the Raspberry Pi's USB, boot it up and log in.
- Follow the instructions in the Bluetooth set up guide.
Follow the instructions in the Wiimote set up guide.
This is the main program that will let you control the rover with the Wiimote. At the command line type nano robot.py. Type, or cut and paste, this program. When you have finished:
Press CTRL-o and then Enter to save
Press CTRL-x to exit to the command line
Now run the program: sudo python robot.py.
If everything is working properly you should be able to control your rover with the Wiimote. If not, go back through the guide and check that each step is working properly.
Now you have a remote-controlled rover, which is completely fantastic, but he looks a little ... rovery. He clearly needs sprucing up and androidifying. How you do this is up to you, but use your imagination to make a robot worthy of having a Raspberry Pi stuck up its bum. Tip: recycling, reusing and repurposing is good! Here's how we made ours:
- Could you automatically run the Python script on startup?
- How about spoken cues so that you know when to connect the Wiimote?
- Could you make your robot speak?



