The first part of this series showed parts used to make low-cost wheeled robots. You can get a lunchbox for very little money, and they make for sturdy small robots.
Their size leads to some constraints. Raspberry Pi Zero W (or WH) fits well in these spaces. The L298 controller is a reasonable balance of cost, size, and ease of use.
A robot builder needs access to a few tools like a ruler, paper, pencil, a drill, some screwdrivers, and a vice/clamp. This build uses consumables like jumper wires, screws, AA batteries, and a standoff kit with M2, M2.5, and M3 types. A hot‑glue gun is also handy.
This article was written by Danny Staple and first appeared in The MagPi issue 85. Subscribe to The MagPi in print for 12 issues and get a free Raspberry Pi. Danny makes robots with his kids as Orionrobots on YouTube, and is the author of Learn Robotics Programming.
Build a low-cost wheeled robot: You'll need
Plastic lunchbox – minimum 90 mm wide × 120 mm long × 60 mm high
Battery box – 6 × AA
5 V 3 A UBEC
Getting familiar with components
Examine the motors. Sticking out of the sides are the axles. On one side, close to the axle, is a small knob which can help lock the motor into position. The top and bottom of the motor is flat. The motors should have connection wires on them, on the opposite side to the knob.
The motor controller has a large metal heat-sink sticking up above the board.
Raspberry Pi GPIO pins should be present and go in face up so they can be used.
A lunchbox is made of thin rigid plastic. It probably has rounded corners. Take measurements using the flat edges.
Planning and test fitting
Test-fit the parts to check the lunchbox is big enough. Make a simple plan for where parts could go.
Put the motors in the box, as shown in Figure 1, with their axles to the rear. Fit your Raspberry Pi Zero in the front space and the motor controller between the motors. The UBEC (which is a DC voltage regulator) sits loosely in the box.
The battery box goes in the top – inside if it can; outside if it interferes with the heat-sink.
The wheels would go on the motors and the castor at the front under Raspberry Pi. Take a photo and remove it all.
Sketches for the motors and castor
Sketches enable you to place holes and components before making any cuts. See orthographic drawing tips.
Find or start a sketch of the motors. Write in dimensions for their size, axle diameter, and location, and the positioning knob on the side.
Sketch a side of the lunchbox, with holes to put motors flush with the inside bottom of the lunchbox. Include dimensions to show relative positions of holes for the axle and knob.
Sketch the bottom of the lunchbox and measure the two mounting holes for the castor to go in the front middle.
You should have two lunchbox sketches with carefully checked dimensions.
Tip! Searching the web for part dimension pictures provides useful sketching start points. Print them and draw more on them, or use them for reference when making other sketches.
Measuring for the electronics
The test-fit photo (Figure 2) is a rough guide on positioning things in the box, but sketches with dimensions have detail on where components should go.
Raspberry Pi has drawings with dimensions online. Add mounting holes for it to your lunchbox bottom sketch near the front, with dimensions for diameter and position.
Measure then sketch the motor controller’s position and holes for the controller on the lunchbox bottom sketch.
Carefully check the bottom sketch. It should have holes for the castor and both electronic boards.
Sketch the top of the lunchbox, where the AA battery box goes.
Drill the holes
Use a vice/clamp! For your safety and a good finish, never be tempted to skip using a vice or clamp for drilling, soldering, or cutting.
Double-check sketch measurements. Use a fine marker pen to measure and make crosses as hole guides on the lunchbox.
Clamp the box firmly with a vice, ensuring the surface to drill is facing upwards. Do not try to hold the box with hands when drilling it!
When making holes, the part may flex, crack, or spin. The drill bit can ‘wander’ from its target. To reduce this, start with the smallest bit to make a pilot hole. Follow through with progressively wider drill bits to the desired diameters. You’ll need to reposition the lunchbox to drill different areas.
Fit the motors and castor
Line up the motor axles and knobs with their holes, then push the axles through. If any holes feel tight, drill them out a little more.
Make a hot-glue line between each motor and the lunchbox to hold it, being careful to avoid getting glue on the axle.
Bolt the castor in place using M3 nylon bolts and nuts with the threads facing outward. Start with two opposite corners if it has four bolts. These bolts go under Raspberry Pi; to avoid short circuits, they must not be metal bolts.
Wiring the motors
The motor board may be harder to access when bolted down, so it makes sense to make the motor connections at the sides first.
Start by loosening, but not wholly unscrewing the connection terminals. Look at the circuit. Push the wires for each motor into the two terminals for that side, and then gently but firmly screw down the terminal so it holds the wire.
It’s a good idea to tug gently on the wires to check they are screwed into the terminal securely.
Fit Raspberry Pi and motor controller
Line up the motor controller with its holes. It may need to slot under the motor axles. Push M2.5 bolts through two opposite corners to line it up, and loosely put nuts on these. Put in the other two corners and tighten them all up.
Don’t tighten nuts past finger-tight, as this can damage the bolts or the parts held by them.
For Raspberry Pi, put M2.5 standoffs thread first into the four holes and tighten nuts to them. Place your Raspberry Pi Zero W over the standoffs. Use the opposite corners method again. Leave these quite loose so your Raspberry Pi can be taken out.
Fitting the battery box
Using the sketch made of the top of the lunchbox, line up the battery box – on the inside if there is space; on the outside if it would stop the lunchbox closing. An extra hole is needed for cables if it’s outside.
Screws could be used, but flat countersunk types are needed, making hot glue an easier option.
Make lines of hot-melt glue between the battery box and lunchbox around the sides of the battery box. There should be no glue inside the battery box, and it should be held firmly once the glue has set.
Wiring the batteries
The battery box connections and UBEC are wired in together. The UBEC has two sets of connections. The input end has thicker wires with stripped ends, and the output connector has a three-pin push-fit connector. Wire the battery positive (red) and UBEC input positive (red) together into the motor controller +12 V or Vin terminal. It helps to twist the two bare ends together before pushing into the terminal and screwing down.
Wire the battery negative (black) and UBEC input negative (black) together into the motor controller GND terminal.
If you want to add a switch, put it between the batteries and the UBEC / motor controller.
Wiring Raspberry Pi
Use the circuit diagram (Figure 3) with Raspberry Pi GPIO pinout as guidance for this step. Physical pin 1 is closest to the microSD slot on Raspberry Pi Zero W boards.
The UBEC three-pin push-fit connects to GPIO so that the empty slot and red wire go to the 5 V pins, with the black wire going to the ground pin.
Use female-to-female jumper wires to connect the Raspberry Pi to the motor controller pins. Connect Raspberry Pi GPIO 17 and 27 pins to motor controller IN4 and IN3 pins.
Connect Raspberry Pi GPIO 23 and 24 pins to motor controller IN2 and IN1 pins.
Finishing the Raspberry Pi robot
To finish assembly of the robot, push the wheels onto the axles.
Line up the wheels so the flat parts of the axles line up with the flat edges in the axle holes. They can require quite a bit of force, so push on the motor and the wheel to deliver it. Do not try to push the wheels on without supporting the motor.
You can now also place the lid on top of the robot. If the lunchbox isn’t quite tall enough, the lid might rest on top – do not force it down.
This robot is built, wired, and waiting for code!
The next part of our robot tutorial will appear in The MagPi 86. On sale 26 September 2019.