Problems trying to communicate with a Digital Servo
hi everyone, i'm trying move 135 degrees 2 savox 1283sg coreless digital servos in opposite directions using 2 push buttons inputs. ran code 2 s3003 futaba analog servos , worked perfectly. sadly not case digital servos. 1 of them moving well, other 1 after first movement freezes. tried find out info , read current draw , stuff, nothing has solved problem.
i'm attaching picture of circuit , actual code.
thanks!
this code:
i'm attaching picture of circuit , actual code.
thanks!
this code:
code: [select]
#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);
}
the servos should have own power supply. shouldn't trying pull power through arduino unless whole purpose of project magic smoke out of arduino.
Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > Problems trying to communicate with a Digital Servo
arduino
Comments
Post a Comment