I try to control 4 servos for rover. 2 servos for the left side and 2 for the right side. The servos on the same side works in the same rotation. I have a problemL The rotation of servo are not stable. If I put 1500microseconds for the neutral position, they move a little.
I connected directly on the arduino pin the wired of the servo. I should put a resistance ?
int sensorIR = 0;
int sensorUS = 1;
int calibIR = 10000;
int valIR;
int servoTU = 8;
int servoLF = 9;
int servoLB = 10;
int servoRF = 11;
int servoRB = 12;
int lastPulseR;
int lastPulseL;
int pulseWidthR = 1250;
int pulseWidthL = 1750;
int refreshTimeServoL = 20;
int refreshTimeServoR = 20;
void servoL(int pulseWidth){
if(millis()-lastPulseL >= refreshTimeServoL){
digitalWrite(servoLF,HIGH);
digitalWrite(servoLB,HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(servoLF,LOW);
digitalWrite(servoLB,LOW);
lastPulseL=millis();
}
}
void servoR(int pulseWidth){
if(millis()-lastPulseR >= refreshTimeServoR){
digitalWrite(servoRF,HIGH);
digitalWrite(servoRB,HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(servoRF,LOW);
digitalWrite(servoRB,LOW);
lastPulseR=millis();
}
}
int readSensorIR(){
return (1000/analogRead(sensorIR));
}
void setup(){
pinMode(servoTU,OUTPUT);
pinMode(servoLF,OUTPUT);
pinMode(servoLB,OUTPUT);
pinMode(servoRF,OUTPUT);
pinMode(servoRB,OUTPUT);
pinMode(sensorIR,OUTPUT);
pinMode(sensorUS,OUTPUT);
lastPulseL=millis();
lastPulseR=millis();
}
void loop(){
servoL(pulseWidthL);
servoR(pulseWidthR);
}