Servos trembling

I’m almost finished a project where two potentiometers positioned itself a couple of servos to rotate on two axes a laser beam, apart from this it indicates the position [0-180] on a Parallax serial display.

Just that I have a problem servos not stop shaking like a little dog in winter, I think I need to add a form to limit how often refreshes the servo position or other idea is may be the source of power but I doubt it because already connected to battery and still shakes.

If it’s the limiter of the servo position, What should do I add and where I should put on the code?

Here is the Code.

const int TxPin = 6;               //Parallax Serial Output
int sensorPinH = A0;               //H Servo
int sensorPinV = A2;               //V Servo
#include <SoftwareSerial.h>        //Serial Library Output
#include <Servo.h>                 //Servo Lib
Servo myservoH;
Servo myservoV;
SoftwareSerial mySerial = SoftwareSerial(255, TxPin); //Define Serial
 void setup()
{
  pinMode(TxPin, OUTPUT);
  digitalWrite(TxPin, HIGH);
  mySerial.begin(9600);
  delay(100);
  mySerial.write(12);                // Clear
  mySerial.write(220);              // Sound
  delay(5);                      	 // Required delay
  myservoH.attach(9);              // attaches the servo on pin 9 to the servo object 
  myservoV.attach(10);            // attaches the servo on pin 10 to the servo object 
}
void loop()
{
 int readingH = analogRead(sensorPinH); 
 float positionH = readingH / 5;                 // now print out the temperature
 mySerial.print(positionH);mySerial.print(" H"); //Print H Position
 myservoH.write(positionH);                      //Positioning H
 mySerial.write(13);                             //Move to 2nd row. 
 int readingV = analogRead(sensorPinV); 
 float positionV = readingV / 5;                 // now print out the Position V
 mySerial.print(positionV);mySerial.print(" V"); //Print V Position
 myservoV.write(positionV);                      //Positioning V 
 delay(100);
 mySerial.write(12); 
}

Regards :slight_smile:

SoftwareSerial turns off interrupts while sends or receives a character. This can cause jitter in the interrupt-driven servo timing pulses. If you use a higher baud rate the interrupts will be off for a shorter period and that might help.