Vex Motors on Arduino

Vex motors (with the Vex Motor Controller 29) are essentially servos. To use them on an Arduino as motors, all you need to do is figure out the “angles” that give you the right speed.

The problem is that all motors are slightly different. To find the right angles for my motors, I simply modified the “knob” example on the Arduino Aplication (1.0.1) to this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <Servo.h> 
 
// create servo object to control a servo 
Servo myservo;  
 
// analog pin used to connect the potentiometer
int potpin = 0;  
 
// variable to read the value from the analog pin 
int val; 
 
// vex motor value
int vex;   
 
void setup() 
{ 
  myservo.attach(11); 
  Serial.begin(9600);
} 
 
void loop() 
{ 
  val = analogRead(potpin);            
  vex = map(val, 0, 1023, 0, 179);
 
  myservo.write(vex); 
  Serial.println(String(val) + "  VEX:" + String(vex)); 
  delay(15); 
}

By adjusting the potentiometer a number of “VEX” angle values are generated, from 0 to 180. Make sure that you have the serial monitor up!

My motor was working at the following angles:
20 degrees: move forward
138 degrees: move backward
91 degrees: stop motor

based on the above findings, we can then test the VEX motor by using the following arduino sketch:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <Servo.h>
Servo Motor; 
 
const int MF = 20;  // angle that moves motor forward
const int MB = 138; // angle that moves motor backward
const int MS = 91; // angle that stops the motor
 
void setup()
{
 // The white pin of the VEX motor controller 29
 // connects to pin 11 (or any other PWM pin)
 Motor.attach(11);
}
 
void loop() 
{
  Motor.write(MF); // move forward
  delay(1000);     
 
  Motor.write(MS); // stop motor
  delay(1000);  
 
  Motor.write(MB); // move backward
  delay(1000);
 
  Motor.write(MS); // stop motor
  delay(1000);   
}