Building a Robot

Pianka Labs
8 min readDec 21, 2020

--

I started building a robot for fun about a week ago, and I’ve decided to document my progress as sort of a how-to guide here.

This article will cover initial design and assembly, with subsequent pieces on code, additional components, and more advanced features as I add them. I only began taking pictures some time into the assembly, so the first few steps will be a little light.

Let’s start by outlining where this project is going: the first milestone is to control the robot from the web or a phone, stream back video, and stream audio bidirectionally; the second milestone is to deploy infrastructure to the cloud allowing me to do those things from anywhere; the third milestone — albeit vague — is to have an autonomous driving mode; after that I’ll layer in more advanced features like OpenCV object recognition and voice control.

It should be an adventure!

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:

Credit: https://create.arduino.cc/projecthub/ryanchan/how-to-use-the-l298n-motor-driver-b124c5

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:

Now for the remaining sensors — as I mentioned toward the start of this article, I want this robot to be able to stream video back to a user, and stream audio bidirectionally. To do that, I need a camera, a speaker, and a microphone. Considering all of the meaningful software will eventually be running on the Raspberry Pi, the simplest solution was to grab some inexpensive USB components for the speaker and microphone.

All I need to do is shorten the cables with a little splicing, some solder, and my trusty hot glue gun:

With some glue, electrical tape, and a little clip, it’s on:

Rinse and repeat for the speaker:

However, mounting the speaker will require a bit more “ingenuity”. Stretching the definition of “standoff” and a few dabs of superglue, I’ve got a makeshift mount:

Now that’s a proper looking robot. All that’s left is to give it vision. I used the standard Raspberry Pi 5MP 1080p camera module — along with an acrylic case — mounted on a few standoffs smack in the middle of the frame. Then reusing my standoff-makeshift-mount technique:

…and actually mounting it:

Boom! I tested the basic connectivity of all the components to ensure they (still) work. The robot is now ready for some software. I’ve completed 95% of the Arduino controller code as of the time of this writing, so the next article will cover a state machine for the motor and the communication protocol between the Raspberry Pi and the Arduino.

Thanks for reading :)

Notes

I buy many of my supplies from All Electronics — they purchase surplus inventories and resell them at a significant discount; it’s not always as nicely packaged as something from SparkFun or Adafruit, but their prices are a fraction of the cost for staple goods.

--

--