Payam TRASH-ROBOT

  • Raspberry Pi 3
  • Motor controller board
  • 2 × 12V DC motors
  • 2 × wheels
  • 1 × AA battery holder (for 4 AA batteries)
  • 4 × AA batteries
  • Ball caster
  • Wire or jumper leads
  • A USB Battery pack
  • Screw driver
  • Soldering iron and solder
  • Wire strippers
  • Small cardboard or plastic box and glue/tape
  • Breadboard
  • VL53L0X time-of-flight range finder or ultrasonic distance sensor
  • 2 × line following sensors
  • 18650 battery, battery clip, USB charge/discharge board (or USB power bank)

Set up the trash-box. Mark the holes for tires. 

Connecting the Rasp with batteri and tire.

Servo setup:

Connecting the board to your Raspberry Pi

The board used in this project needs to be wired to the Raspberry Pi. Other boards may connect differently, and some boards can simply be placed onto the Raspberry Pi GPIO pins as a HAT. Make sure you look at the documentation for your board to see whether this is the case.

On the board used here there are pins labeled In1In2In3, and In4, as well as two GND pins. Which GPIO pins on your Pi that you use is up to you; in this project, GPIO 789, and 10 have been used.

Image result for raspberry pi gpio
GPIO pin connects to board pin
7 <–> In1
8 <–> In2
9 <–> In3
10 <–> In4
GND <–> GND

Rasp PI 2 B+ – GPIO schema

Simple python script:

from gpiozero import Robot
robby = Robot(left = (7, 8), right = (9, 10))

Save your file and call it robby.py or similar. You can then run it by pressing F5 on your keyboard.

Now switch over to the shell and type the following to observe which way the motors turn.

robby.forward(0.4)
robby.right(0.4)

If the right motor spins, you’re good; if not you’ll need to swap them round by swapping the pin numbers in your original script:

robby = Robot(left = (9, 10), right = (7, 8))

Next check your motors are both turning the right direction:

robby.forward(0.4)

robby = Robot(left = (9, 10), right = (8, 7))

Now we’re ready to put the bot together – there’s many ways to construct a chassis, from 3D printing to laser cutting, but first it’s best to use a cardboard box to get the hang of the layout. Experts recommend a chocolate box because the card is nice and rigid, but the choices are endless!

The chassis needs to contain the Raspberry Pi, motor controller and batteries, and needs to allow a pair of wheels to be mounted. Cardboard also allows you to experiment with fitting sensors later on, such as a couple of line sensors, and an ultrasonic distance sensor or a lidar sensor.

You’ll essentially end up with a motor on each side at one end of the box, attached to an external wheel, and the ball caster at the front. Locate your USB power bank in the box, along with the Pi, controller board and motor battery pack.

You should now be able to boot your Pi (from the USB pack) and begin to program it.

There are five basic commands to move your robot, that can be combined to make it move in different ways:

robot.forward()
robot.backward()
robot.right()
robot.left()
robot.stop()

For example, here’s a simple script to make it go in a square shape (although you may need to tweak the sleep functions to get the motions correct).

from gpiozero import Robot
robot = Robot(left = (7, 8), right = (9, 10))
while True:
robot.forward()
sleep(3)
robot.stop()
robot.right()
sleep(1)
robot.stop()

Thanks to the Raspberry Pi foundation for the official Robot buggy project.

Leave a Reply