Go Down

Topic: servo motor jumping (Read 317 times) previous topic - next topic

goran66

Sep 16, 2020, 03:36 pm Last Edit: Sep 16, 2020, 04:07 pm by goran66
Hi,

I´m using a Arduino One board and a micro servo and the original "sweep code".
The board is connected to the USB. Someone on the forum suggested to attach the servo to a separate 6 V and ground to the board ground - but the same problem.

My problem:
It runs OK during the 1st loop and the 2nd - but at the end of the 2nd and before the servo is going back it just "jumps up 5 degrees and back 5 degrees" before it goes back.
How can I avoid this little jump?  

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}


Thanks,
Goran

groundFungus

#1
Sep 16, 2020, 04:56 pm Last Edit: Sep 16, 2020, 04:57 pm by groundFungus
Servos do not, necessarily, go to 0 or to 180 degrees.  You may need to, experimentally, determine the actual range of the servo an adjust your code accordingly.
You will save everyone's time if you read and follow the forum guidelines.  :)          
https://forum.arduino.cc/index.php/topic,148850.0.html
and
https://forum.arduino.cc/index.php?topic=97455.0

slipstick

First loop/second loop? Do you mean it goes from 0 to 180 then back from 180 to 0 and THEN it "jumps" before starting back towards 180?

I've never seen a servo do that but perhaps 0-180 is too much for whatever servo you're using. Try changing it to 5-175 or even 10-170.

Steve

goran66

Thanks everyone. I think I should explain little better next time.

goran66

#4
Sep 16, 2020, 08:42 pm Last Edit: Sep 16, 2020, 08:46 pm by goran66
Hi,
Thank you "slipstick" and "GroundFungus".

That solved the problem - but I still dont know why.

The original code was: 0 to 180 degrees but since I only wanted 0 to 80 degrees
I used those numbers but it didnt work.

So as you suggested: "try to some  other values".  I changed to 10 to 90 degrees - and it
worked so well.

Many thanks,
Goran


Go Up