Mid-Senior Engineers: Reinvent your career with Robotics, earning $100k-$200k+ in the next 90 days. Learn More

Hack your Hexbug with Arduino Control

Liz Miller Learn Robotics

About the Author, Liz Miller, Founder/CEO @ Learn Robotics

Liz graduated with a degree in Robotics Engineering from Worcester Polytechnic Institute and researched drones at UPenn's GRASP Lab. Liz is a former Raytheon Engineer, where she managed major $MM automation projects worldwide. Today, she's the driving force behind Learn Robotics, offering the Robotics Career Blueprint for Engineering Professionals and beginner courses through the Online Robotics Class. Liz is a third-generation entrepreneur who is all about the application of innovation in robotics, automation, and AI. Follow Liz on LinkedIn and Facebook.

Disclosure: Some of the links below are affiliate links. This means that, at zero cost to you, Learn Robotics will earn an affiliate commission if you click through the link and finalize a purchase. Learn Robotics is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a way for websites to earn advertising revenues by advertising and linking to Amazon.com.

Join our Private Discord Server, MakeRobots! Sign Up

Hack your VEX Pick & Drop with Arduino Control

I had this really cool idea to make the VEX Pick & Drop kit “automated” by incorporating a motor on the crank shaft.

Vex Pick and Drop with Arduino

Rather than manually control the arm movements, we’ll program an Arduino Nano (aff. link) to make the system move.

If you haven’t already assembled your kit, follow these instructions to put it together. Then, when you’re finished, come back to this tutorial, and add in the Arduino control.

Before we get started, it’s recommended you have a fundamental understanding of Arduino programming and how to configure a breadboard for prototyping.

If you’re confident in both of those subjects, let’s continue!

Step-by-Step Guide to Add Arduino Control to your HEXBUG

Remove the Crank

We’re going to replace the manual crank with a motor controlled by the Arduino. Disassemble the crank mechanism on the HEXBUG.

Vex Pick and Drop with Arduino

Add a VEX motor to control the rotating shaft

Attach the VEX Motor to the side of the Hexbug using two motor screws. Run a long, square shaft through the center of the assembly. Be sure that the bevel gear lines up with the vertical shaft.

Vex Pick and Drop with Arduino

Note that the motor not only controls the 3 claws, but it also dispenses balls from the chute to the pick up point. There is a plastic “flipper” that rotates and moves the dispenser door. Align the ball flipper so that it’s center with the dispenser door.

Connect the motor to your Arduino

Connect the Arduino Nano to the breadboard. Then wire the motor to the breadboard. We’ll  power the motor off of the Arduino’s 5V output. The motor is connected to digital pin D3. I added a 10KΩ resistor to pin D3 to prevent a current spike during power up.

The motor is connected to the breadboard using Motor Controller 29. You could also use an L298N controller. Connect one end of the motor into Motor Controller 29. Connect the other end of Motor Controller 29 to the breadboard. The pins (left to right) are Ground (GND), Power (VCC), Signal (SIG). Signal is connected to digital pin D3.

Here’s a simple wiring diagram for our setup

Vex Pick and Drop with Arduino

Program the Arduino

Now that we have everything configured, we are going to step into the programming of this motor. First, download the Arduino IDE on your computer. Then, follow along with these programming steps.

Setup your code

First, we’ll start off this sketch with a quick comment at the top of the code. Comments start and end with a forward-slash (/) and an asterisk (*).

 * VEX Pick & Drop Automation with Arduino
 * Demonstrates the use of Arduino with a VEX Hex Bug Mechanics set.
 * We used the Pick & Drop Construction Set with an Arduino Nano.
 * Materials List
 * Arduino Nano
 * VEX motor module VB-1
 * VEX motor controller 29
 * Breadboard
 * Micro USB Cable
 * 10K pulldown resistor
 * Jumper cables
 * LCD Display (Status)
 * Written by Liz Miller
 * Last Modified 11/5/17

Initialize your Motor Pin

Then, define your motor as a Global Variable. Remember, the motor is plugged into digital pin 3 on the Arduino Nano. Therefore, we will set the variable, motor equal to 3. “int” is the variable type of the declaration. It tells the controller that motor is a whole number.

int motor = 3;

Next, add your motor to the setup() method as an OUTPUT. You must do this for all devices connected to the Arduino.

void setup(){
   pinMode(motor, OUTPUT); //add this line
   digitalWrite(motor, LOW) //set the motor OFF initially

Create a new method, called runMotor(), that, you guessed it, runs the motor. We’re going to control the speed of the motor and how long the motor is running by providing two input parameters, speedM and timeM, respectively.

void runMotor(int speedM, int timeM){
   analogWrite(motor, speedM);
   trigger = 1;
      analogWrite(motor, 0);
      trigger = 0;

You’ll notice we’ve included a new variable called trigger that will allow us to shut the motor off when the duration is over. When trigger is 1, the motor will be off; when trigger is 0, the motor is on.

NOTE: You will need to declare trigger in your list of global variables (under your motor declaration).

// add this line to your global variables
int trigger = 1;

Call the method in loop()

Call the runMotors() method in your loop() method. The loop() method runs through each line of code sequentially from top to bottom and then repeats forever. (So as soon as it’s done executing the last line, the first line is executed, and so-on.)

Remember to provide a speed and duration for the runMotors() method. Time is always in milliseconds (1000 milliseconds = 1 second).

void loop() {
   runMotor(125, 10000); //the motor will run at "125" speed for 10-seconds

Finally, save, Compile, and Upload your code. Click the “check” in the top left corner to compile. Then press the “arrow” to upload the code to your Arduino.

If everything is working properly, then you should see the motor turn on, the square shaft spinning, and the claws picking and dropping the ping-pong balls. If not, then go back through the tutorial and do some troubleshooting. If you have a question, leave it below, and I’ll be sure to provide you some feedback!

I hope you enjoyed this tutorial on how to Hack a Hexbug VEX Pick and Drop Ball Kit. If you liked this tutorial, be sure to check out my other articles using Arduino.

Experienced Engineer (Mechanical, Electrical, Computer, Software): If I offered to help you upgrade your engineering career to robotics, earning $100k-$200k+ in the next 90 days, would you take me up on that offer? Click here for details.
Liz Miller Learn Robotics

🚀 Pre-Launch: Become a "MakeR" with MakeRobots!

Hey Reader, 👋

Liz Miller, Founder/CEO, here with some Exciting News!

Learn Robotics just acquired MakeRobots™, an Online Robotics Community, and are prepping its Official Learn Robotics Debut in Late 2023.

MakeRobots™ is your one-stop-shop for learning, gaining coding, electronics, and robotics skills, connecting, and building robots for one low monthly membership!

Join MakeRobots™ at our Special Pre-launch Rate!
🤖 Access our Private Community & Robotics Courses
💬 Network, Collaborate, Connect with Other Makers
🔓 Only $5.99/month – locked in for life
⏱️ Pre-launch deal is Limited to the first 1,000 subscribers

This is a perfect opportunity for you to get into the fastest growing robotics community on the internet, at our ground-level, pre-launch membership rates.

👇 Click the button below to Claim your Pre-launch Membership and become a MakeR in the MakeRobots Community, today!

Learn Robotics Botly Favicon


Coursera Plus is a new subscription service for online courses
Liz Miller

What is Coursera Plus?

Coursera rolled out a subscription service called “Coursera Plus.” Rather than pay per course, the subscription gives you access to 2,000+ courses and Specializations. Is Coursera Plus worth the subscription fee? Find out in this article.

Read More »