The following is the code that is used for my 4 servo robot arm which can be controlled using a Bluetooth application. For example; when I try to move the first servo the others are jittering and they are having a little fluctuation. The same happens for others too. Is there any way to avoid this? Please help!
#include <SoftwareSerial.h>
#include <Servo.h>
Servo myservo1, myservo2, myservo3, myservo4;
byte serialA;
int bluetoothTx = 10;
int bluetoothRx = 11;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
myservo1.attach(3);
myservo2.attach(4);
myservo3.attach(5);
myservo4.attach(6);
//myservo5.attach(7);
//myservo6.attach(8);
Serial.begin(9600);
bluetooth.begin(9600);
}
void loop()
{
if (bluetooth.available() > 2) {serialA = Serial.read();Serial.println(serialA);}
{
unsigned int servopos = bluetooth.read();
unsigned int servopos1 = bluetooth.read();
unsigned int realservo = (servopos1 *256) + servopos;
Serial.println(realservo);
if (realservo >= 1000 && realservo <1180){
int servo1 = realservo;
servo1 = map(servo1, 1000,1180,0,180);
myservo1.write(servo1);
Serial.println("servo 1 ON");
delay(10);