How to hook up a VEX motor to Arduino

So I was trying to hook a vex motor up to a Arduino Mega micro controller and found the process much harder than I thought it would be, so I will post a tutorial on how to do it.

So I am guessing many of you are saying “there is an analog out command why not just use that?” When I tried it, it did not work. I do not know why it did not work, but may work on that problem in the future.

It is possible to use Tone to control the motors because it acts like a pulse signal.

Vex states that “Full Reverse is at about 1 ms, Neutral is at about 1.5 ms and the Motor will be at Full Forward at about 2 ms.”

Using this information it is possible to say that if you were to play a 500Hz tone, it would run full reverse because a single cycle would take 2ms, but the positive part of the square wave would only be 1ms.

From this we get the equation 500/(((-vexSpeed)+128)/256+1)
with vexSpeed being defined between -128 and 127

Now we can move on to discribing the hardware setup:

You will need an Arduino microcontroller, a 9v battery, and a power bus

*]Connect the PWM (white) cable of the motor to a PWM pin on the Arduino. See for supported pins
*]Connect the ground (black) cable of the motor to the ground side of your power bus
*]Connect the power (red) cable of the motor to the power side of your power bus
*]Run a jumper wire from the power side of your bus to the Vin
*]Run a jumper wire from the ground side of your bus to the ground input
*]Connect your 9V battery to the power bus with ground-ground and power-power


analogWrite creates a continuous pwm waveform at about 490Hz, you could send this to some motor drivers, but not an MC29. It’s also a bit on the slow side for motor control, the MC29 creates a pwm signal at approx 1200Hz, I usually use something like 15kHz.

The 1.5mS (1mS to 2mS) signal needs to have a duty cycle of about 18mS, that is, a pulse every 18mS of 1mS to 2mS in duration. Some motor controllers will allow the duty cycle to be as low as 3mS, not sure what the MC29 accepts.

Are you trying to use an MC29 or some other type of motor driver?

During a test with a old 3 wire motor, I was using constant tones (no 18ms gap) and was able to control the motor correctly. Below is a video of a the motor running at different tone frequencies from 250Hz to 500Hz. Natural falls at 333Hz which is why it is travels a farther distance after this than before.

Hey, since you are driving a 3-wire motor, why would you not just use the Arduino Servo library?

It was created to drive exactly this type of device, and will also work with an MC29.


  • Dean

I guess I could have used that and probably will in the future. I had assumed that analogWrite was what I should use and when that did not work, I made my own method.