Hack your Hexbug with Arduino Control

Disclosure: Some of the links in this post 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.

Table of Contents

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.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Learn Robotics Online
— Get 2 months free!

Exclusive Limited Offer for Serious Beginners Ready to take their Hobby to Engineering Internships, $100k+ Careers, and Beyond!

Enroll now, and earn your first robotics certificate in the next 7 days.

👇 Click below to claim this deal.