user8645307
user8645307

Reputation:

Servo movement from side to side with PWM Arduino uploaded code

I'm using Arduino-Uno micro-controller with Adafruit servo shield. To move a quite fast 0.07 sec/60° mini digital servo motor with desired angle, for example from C# application:

myport.WriteLine(val.ToString());

I using PWM library:

pwm.setPWM(1, 0, Serial.parseInt());

Which moves motor to the assigned angle successfully, but I'm trying to figure out, how to move servo motor from one angle to another with full reaching of end points from uploaded code.

So if maximum and minimum of range is:

#define SERVOMIN  160
#define SERVOMAX  500   

And servo motor performs from 210 to 450, here is a my attempt:

pwm.setPWM(1, 0, 210); 
delay(12); 
pwm.setPWM(1, 0, 450);  
delay(12);
pwm.setPWM(1, 0, 210);  

This way motor does not completes movement or even makes single direction movement without return. What should be a proper way, to make such movement within uploaded code.

Any advice, guide or example would be very helpful

Upvotes: 0

Views: 390

Answers (1)

gre_gor
gre_gor

Reputation: 6809

You can't.

Normal servos don't provide any feedback on their position. It's not possible with software alone, unless you add long enough delay to make sure it completes the move even under load.
You either need a different servo or additional sensors.

More on Arduino Stack Exchange: How long does it take for a servo to change rotation?

Upvotes: 2

Related Questions