Hi everyone, I'm trying to move 135 degrees two Savox 1283SG Coreless Digital servos in opposite directions using two push buttons as inputs. I already ran the code with two S3003 Futaba analog servos and they worked perfectly. But sadly this is not the case for the digital servos. One of them is moving well, but the other one after the first movement freezes. I tried to find out info and I read something about current draw and all that stuff, but nothing has solved the problem.
I'm attaching a picture of my circuit and the actual code.
Thanks!
This is my code:
#include <Servo.h>
#define SERVO_LEFT 3
#define SERVO_RIGHT 5
#define DOWN_BUTTON 7
#define UP_BUTTON 9
#define LEFT_OPEN 180
#define LEFT_CLOSE 45
#define RIGHT_OPEN 0
#define RIGHT_CLOSE 135
#define SLOPE .8
#define INITIAL_SERVO_POS_LEFT LEFT_OPEN
#define INITIAL_SERVO_POS_RIGHT RIGHT_OPEN
Servo servoLeft;
Servo servoRight;
int buttonstate1;
int buttonstate2;
float angle1;
float angle2;
bool button1;
bool button2;
float delta(float start, float stop, float slope)
{
return start + (stop-start) * slope;
}
void setup()
{
// Initialize arduino pins
servoLeft.attach(SERVO_LEFT);
servoRight.attach(SERVO_RIGHT);
pinMode(DOWN_BUTTON, INPUT);
pinMode(UP_BUTTON, INPUT);
// Initial servo posiotion
angle1 = INITIAL_SERVO_POS_LEFT;
angle2 = INITIAL_SERVO_POS_RIGHT;
servoLeft.write(angle1);
servoRight.write(angle2);
// wait 1 second
delay(1000);
}
void loop()
{
// Read input
buttonstate1 = digitalRead(DOWN_BUTTON);
buttonstate2 = digitalRead(UP_BUTTON);
if(buttonstate2)
{
button2 = true;
button1 = false;
}
if(buttonstate1)
{
button1 = true;
button2 = false;
}
// Action
if(button2)
{
angle1 = round(delta(angle1, LEFT_OPEN , SLOPE));
angle2 = round(delta(angle2, RIGHT_OPEN, SLOPE));
servoLeft.write(angle1);
servoRight.write(angle2);
if(angle1 == LEFT_OPEN)
{
button2 = false;
}
}
if(button1)
{
angle1 = round(delta(angle1, LEFT_CLOSE , SLOPE));
angle2 = round(delta(angle2, RIGHT_CLOSE, SLOPE));
servoLeft.write(angle1);
servoRight.write(angle2);
if(angle1 >= LEFT_CLOSE)
{
button1 = false;
}
}
// delay(100);
}

