Servo stops working after first rotation
i've got 5v arduino nano (it still works despite it's age) hooked dgservo s05nf std , i'm trying rotate 180 , 0 after receiving serialevent. rotation sort of works, starts twitch , forth few seconds , doesn't receive more serialevent calls. if comment out servo calls, builtin led works fine indicator, , serialevent works on several messages. using usb supplied 5v , tested sweep successfully.
any thoughts appreciated:
any thoughts appreciated:
code: [select]
#include <servo.h>
const int servo_pin = 9;
servo servo;
int pos = 0;
string input = "";
bool inputcomplete = false;
bool servorunning = false;
unsigned long pmillis = 0;
const long delay = 3000;
void setup() {
serial.begin(9600);
input.reserve(200);
servo.attach(servo_pin);
}
void loop() {
if (inputcomplete) {
if (input.equals("d")) {
initservo();
}
input = "";
inputcomplete = false;
}
if (servorunning && millis() - pmillis > delay) {
returnservo();
}
}
void serialevent() {
while (serial.available()) {
char inchar = (char)serial.read();
if (inchar == '\n') {
inputcomplete = true;
} else {
input += inchar;
}
}
}
void initservo() {
pmillis = millis();
servorunning = true;
digitalwrite(led_builtin, high);
servo.write(180);
}
void returnservo() {
servorunning = false;
digitalwrite(led_builtin, low);
servo.write(0);
}
a servo can suck more power standard usb port can provide. usb supposed give 500ma negotiation , 100ma without. nano doesn't attempt negotiation.
power separate supply - phone charger source of 5v. have higher current limit.
power separate supply - phone charger source of 5v. have higher current limit.
Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > Servo stops working after first rotation
arduino
Comments
Post a Comment