Building a Robot
By: Pianka Labs
Tags: Arduino, Raspberry Pi, Robots

Here is the list of parts I used (sans wires, adhesives, etc.):

I’ve included some notes at the end for suggestions on wires, connectors, stand offs, and other useful accoutrements. You can definitely get away with much smaller & less expensive hardware — I just happened to have these on hand already (plus they look cool).

The Chassis and Motors

The chassis I used was a fairly straightforward assembly. I actually thought it would be bigger when I purchased it, so assume at some point I will plan to build a bigger robot. Fully assembled it will look like this:

Credit: Amazon.com

Once the chassis is assembled, it’s time to wire up the motors, power supply, L298N controller, and Arduino. Rather than build a motor controller from scratch with MOSFETs, diodes, capacitors, etc. the L298N integrated circuit is a dual-channel H-bridge that will allow you to control the speed and direction of two DC motors “out of the box”.

Credit: Amazon.com

The pinout for the L298N module is as follows:

OUT1 — left motor negative terminal

OUT2 — left motor positive terminal

OUT3 — right motor negative terminal

OUT4 — right motor positive terminal

12V — positive (red) from the 18650x2 battery pack

GND — negative (black) from the 18650x2 battery pack

5V — unused, output could be to made to power the Arduino

ENA — right motor speed control, Arduino pin 2

IN1 — right motor pin 1 (high forward), Arduino pin 3

IN2 — right motor pin 2 (low forward), Arduino pin 4

IN3 — left motor pin 1 (high forward), Arduino pin 5

IN4 — left motor pin 2 (low forward), Arduino pin 6

ENB — right motor speed control, Arduino pin 7

And here’s a visual diagram (using Fritzing) that shows the connectivity:

Note that the two ground pins for the Arduino and the L298N must be connected so they have the same baseline for voltage. The chassis battery pack fits two 18650s to power the motors.

Thank you to Ryan Chan for writing an Arduino test script for the L298N! I’ve modified his slightly for my pinout:

The motor pins are digital and are written out as either HIGH (5V) or LOW (0V); swapping which is HIGH and which is LOW will reverse the direction of the motor. As you can see, I wired the terminals to PWM pins for convenience but the effect is the same as were they digital. The speed control pins are actually PWM and a value between 0 and 255 will set each motor somewhere between stop and full speed — consistent with the voltage supplied. In this case, both the L298N module and the DC motors are rated for a full 12V, however I’m only supplying 7.4V and it still has some pretty decent kick.

Check out the chassis and motors test in action:

Not bad.

Mounting the Components

Next it’s time to make the wiring a little more elegant, and start putting these components onto the chassis. I’ll start by simplifying the connections between the Arduino and the L298N module. First, some pin headers/connectors:

Add a ribbon cable, solder, and hot glue:

Then some shrink wrap so it looks pretty(ish):

And voilà:

Then I’ll add some wires to connect the OUT# pins to the motor terminals:

With that done, I can mount the major components. I’m missing pictures of these steps, but if you look at the chassis:

Credit: Amazon.com

…I put the L298N directly on the frame to the right side of that picture — the back of the robot. Above it vertically, mounted using standoffs, is the Raspberry Pi. To the left, also mounted with standoffs, is the Arduino — the front of the robot. I put the battery pack underneath the frame to save space for more components. Then I just connect the wires, and it’s starting to look like a real robot.

After all that, this is what I have:

I intentionally designed everything so it could be disassembled if necessary without breaking soldered wire splices or removing any form of adhesive. So without further ado, the robot’s maiden voyage:

(with a portable battery pack on the Raspberry Pi for the moment)

Pretty cool.

UPS HAT, Camera, Speaker, and Microphone

The remaining components I’m adding serve two purposes: to secure an additional power supply for the non-motor components, and to add sensors & “actuators” for use in upcoming features. First is a UPS (uninterrupted power supply) HAT (hardware attached on top) that — ironically — will be attached underneath the Raspberry Pi. It also takes two 18650 batteries, and can disburse power while charging.

On the other side of the HAT board are some circular spring-loaded contacts (upper right in gold):

…that line up with six of the GPIO pins on the Raspberry Pi, seen here (upper left in silver):

Those connections will handle all of the power management between the UPS HAT and the Raspberry Pi. After putting some standoffs and plexiglass in place to secure it all, it lights up beautifully: