Hi i am new to using arduinos and am currently trying to make a robot arm using 4 micro servos.
I am using a PCA9685 board to connect the servos to arduino and i have 4 potentiometers too control them but whenever i run the code, my servos randomly jitter and move about
code I am using:
#include <Wire.h>
// Include Adafruit PWM Library
#include <Adafruit_PWMServoDriver.h>
#define MIN_PULSE_WIDTH 650
#define MAX_PULSE_WIDTH 2350
#define FREQUENCY 50
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// Define Potentiometer Inputs
int controlA = A0;
int controlB = A1;
int controlC = A2;
int controlD = A3;
// Define Motor Outputs on PCA9685 board
int motorA = 0;
int motorB = 4;
int motorC = 8;
int motorD = 12;
void setup()
{
pwm.begin();
pwm.setPWMFreq(FREQUENCY);
}
void moveMotor(int controlIn, int motorOut)
{
int pulse_wide, pulse_width, potVal;
// Read values from potentiometer
potVal = analogRead(controlIn);
// Convert to pulse width
pulse_wide = map(potVal, 0, 1023, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
pulse_width = int(float(pulse_wide) / 1000000 * FREQUENCY * 4096);
//Control Motor
pwm.setPWM(motorOut, 0, pulse_width);
}
void loop() {
//Control Motor A
moveMotor(controlA, motorA);
//Control Motor B
moveMotor(controlB, motorB);
//Control Motor C
moveMotor(controlC, motorC);
//Control Motor D
moveMotor(controlD, motorD);
}
Battery shown should be ample.
We use similar with 1/4 of the shown mAh capacity on 6 channel rc aircraft with no drama.
I'd go more for the breadboard and the flimsy jumper leads everywhere.
You might also replace the pot variable with a constant and see if they still jitter. And disconnect all but one servo looking for jitter then add another servo .....etc
No, if such servos jitter, it is nearly always a matter of the controlling pulses. If these pulses are not stable, the servo will jitter.
That should be done to see the cause of the jitter. Probably they will not jitter if you do so.
Reading an analog value will usually not give stable result without filtering. Calculate an average value over several measurements.
Also changing from one analog input to the other with Arduino controllers can cause this problem.
Because there is only one ADC it is switched from input to input, it takes time, due to an input capacitor, for the new voltage level to stabilise.
It has been found that reading the same input twice and only using the last reading, can negate this.
That is why I suggested the code change in post#14.