Introduction: RSPI Push-Button Robot Buggy
Have you ever seen a remote control car at the store and wondered if you could build one yourself. Well yes you can build one and control your car with push buttons. All you need a some simple materials and you could build yourself a push-button robot buggy. Now follow the steps bellow and build your push-button robot buggy.
Step 1: Gather Materials
Before we begin, you should gather the need material to complete this project:
- Raspberry Pi B+
- Half sized Breadboard
- Phillips screwdriver
- Robot Buggy chassis with 2 motors
- 4 push buttons
- 9 volt battery
- Portable Charger
- Micro USB wire
- 4 Male - Female Jumper-wires
- 12 Male - Male Jumper-wires
- Python 3 coding software
- Mobile Device that can download VNC viewer app
Step 2: Set-up
Once you have gathered the needed materials, now you can build your buggy. Firstly, you need to connect your Raspberry Pi to your monitor, mouse and keyboard. Once you do that, you need to attach your t-cobbler to your Pi and your half sized breadboard. Now you can attach your h-bridge and push buttons to your breadboard.
Step 3: Connecting the Buggy to the H-bridge
Now you are ready to build your buggy. First you need to attach the motors to the h-bridge, so you need to unscrew the four blue ports on the top and bottom of the h-bridge, if you are holding it like it is in the image above. After that, then you need to get two red and two black male-male jumper-wires. Next put the black wires in the left ports and the red wires in the right ports (in the image above it was wired the other way around, but this way makes it easier). Once you place the wires in the blue ports, screw them in tight, which will help prevent them from falling out. Now on your chassis, near the wheels you will see the motors and a red and black female connector coming out of each motor. Match up the red and black wire from the h-bridge to the motors and now your h-bridge is connected to your buggy. Remember that if you are holding your h-bridge the same as the image above, the top ports should be connected to the left wheel and the bottom ports should be connected to the right wheel.
Step 4: Connecting Your H-bridge to Your Raspberry Pi
Once you have connected your H-bridge to buggy, now you connect it to your Pi. Now you need 4 male-female jumper-wires. Connect all four jumper-wires to the h-bridge to the male connectors on the front of the h-bridge. Then connect all four wires to different GPIO on your breadboard. I used GPIO 4 and 17 for the left wheel and GPIO 5 and 6 for the right wheel. To know which wires are for which wheel, on the h-bridge which two male to female wires you connected are closer to the male to male wires you connected to the motor, are the assorted wheel. Now you need a male to male wire to attach a ground wire to your h-bridge. Which means now you need to unscrew the middle port of the three front ports of your h-bridge. Then now place your wire in and screw it in tightly to prevent it from falling out. Now place that wire into a ground port in your breadboard.
Step 5: Connecting a 9 Volt Battery to Your H-bridge.
The last thing you need to do to complete building your buggy is to attach a 9 volt battery. You need a connector that connects your battery and splits it into ground and voltage. Now you need to unscrew the from the left, first two ports on your h-bridge. After that you need to put in the red wire from the battery into the left port and then put the ground wire into the middle port. You should have two wire in the middle port, one ground wire to the Pi and one ground wire from battery. Now screw the ports back tightly and move on to the next step.
Step 6: Checkpoint
Now we are going to check if your buggy is working before we move onto the push buttons. So now open Python 3 on your Pi and run the code below to ensure your buggy works.
from gpiozero import Robot
robby = Robot(left=(4,17), right=(5,6))
If your buggy moves forward, now type:
Step 7: Wiring Push Buttons
After checking that your buggy works, you are now ready to add push buttons. First thing you need to do is put a wire from ground and connect it to the ground rails on both sides. This would make it very easy when wire your buttons. Now place your four buttons in the same order as the photo above. Make sure that each leg of each button is in a different row. Now connect one leg from each button to ground. After that you need to connect each button to a GPIO, so we are going to call the button furthest away from your Pi forward and connect that button to GPIO 23. Then the button to the right of the one you just connected, we will call it right and connect it to GPIO 13. Next the button closest to your Pi, we will call backwards and connect it to GPIO 21. Lastly the last button we will call left and connect it to GPIO 18.
Step 8: The Code
After wiring the push buttons, you are ready to code your buggy. Open python 3 on your Pi and follow the code bellow to make sure your buggy works.
from gpiozero import Robot, Button
from time import sleep
from guizero import App, Pushbutton
robby = Robot(left=(4,17), right=(5,6))
forward_button = Button(23)
right_button = Button(13)
left_button = Button(18)
Backwards_button = Button(21)
Step 9: Setting Up VNC Viewer
Now you need to connect your Pi to your phone for you to be able to run the code from your phone once your Pi is attach to your buggy. First download the VNC viewer app on your phone. Then click on VNC on your Pi, it should be near the bottom left of your screen. Once you do that, then type in your Pi address, username and password. Now you are connected to your Pi.
Step 10: Assembling Your Buggy
The last step you need to do is assemble your buggy. This might be the hardest part of this project, because it is a little challenging to get everything to fit on your chassis. For what I did, first I taped the battery at the bottom, between the motors. Then I put the portable charger on the bottom and plugged it into the Pi. I put the Pi and the back of the chassis and taped the h-bridge to the t-clobber. Then I put the breadboard at the front, to make control the buggy easy. But you don't have to assemble yours the exact same depending on the size of your chassis. Now you have finished building a push button robot buggy with your Raspberry Pi.