HS-422 Servo Motor Keeps setting itself at 0 degrees after each angle callout.

Hi Everyone.

So I have a servo motor, HS-422:
Amazon.com: Hitec RCD 31422S HS-422 Deluxe Servo: Toys & Games

And I am currently running this simple code:


#include <Servo.h>

int servopin = 3;
int servoPos = 0;
Servo MyServo;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
MyServo.attach(servopin);
}

void loop() {
// put your main code here, to run repeatedly:
Serial.println("What angle for the Servo?");
while(Serial.available()==0){
}
servoPos = Serial.parseInt();
MyServo.write(servoPos);
}


When i first ran the code with the servo powered by the Arduino, it worked as intended. However, a day later, I ran the same code through the Servo, powered by the Arduino again. What it does now is that after I give the servo an angle, it rotates to that angle for a split second and then resets at the zero position.

I read online that a possibility could be the draw current is insufficient. I have a DC power supply in possession and I was wondering if that would be useful as a power source instead of the UNO. I tried it with the power supply and I still get the same result. I have the negative terminal of the power supply commonly grounded to the arduino's ground.

Does anyone have any ideas what may be going wrong?

Is the Serial monitor set to "No line ending"?

Steve

No it was not. It is working now. Thanks!

The best way to parse for integer input is to skip characters until a digit - then you won't be
confused by extra blank lines or line feeds or whatever. parseInt is extremely crude.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.