Linear actuator jitters/vibrates when getting PWM from Arduino Mega 2560 through JKR 21v3 motor controller I recently bought this linear actuator and motor controller from Pololu:


Linear actuator
Motor Controller JRK21v3


There are several steps that I have to follow in order to set this thing up before I can test it. These instructions can be found here: Pololu JRK USB Motor Controller User’s Guide » Setting Up Your System

I would like to program this using PWM method because I would like to keep the Serial RX for other sensors.  From my little experiment, by using a potentiometer, I noticed this pattern:

Position: Voltage 


Fully extended : 0 V
At Rest : 2.35V
Fully Retracted  : 4.77V.


For this system, I will be controlling it using a PS2 controller. So, by using only the Y_axis of the analog joystick of a PS2 Controller (Up: 0, Rest: 128 and Down: 255), I program it as follows:

//Move Linear Actuator with PS2 on JRK21v3 Controller

#define pwm 6           //red wire 
#define dir 7           //yellow wire

//PS2 controller
#include &lt;SoftwareSerial.h&gt;
#include &lt;Cytron_PS2Shield.h&gt;

Cytron_PS2Shield ps2(10, 11); // SoftwareSerial: Rx and Tx pin

void setup()
{
  pinMode(pwm,OUTPUT);

  ps2.begin(9600); 
  Serial.begin(9600); 
}

void loop()
{
  int Y_axis = ps2.readButton(PS2_JOYSTICK_RIGHT_Y_AXIS);  // 0 - 255
  Serial.print("Y_axis:");
  Serial.println(Y_axis);

  analogWrite(pwm, Y_axis);
}


When I tested it, the linear actuator jitters/vibrates when it is at rest position. What could possibly cause this? Is it the duty cycle due to the PWM? How can I fix this or are there any other better methods?
I got this working using the Servo library. 


You set the input method to PWM.
Connect your RX on the motor controller and hook it up to the servo pin.
Connect the ground of the Arduino to the ground of the JRK 21v3.
Then use the knob servo sample by hooking up a pot to a Arduino.
The calibrate the JRK 21v3 by selecting learn.


Now you can use the actuator as a servo.