servo - fading movement - HELP...

hey.

my name is david and im an arduino beginner. but, i want to program a servo for my new movieprop.
here is a link of the movement:

the movements should be very smooth at the end.
like so:
fading in - full speed - fading out.

i have written some steps with different speeds.
it works in one way, but when the loop begins to repeat the movements, everytime a have a little break in the movement.

#include <VarSpeedServo.h>

VarSpeedServo myservo;

void setup() {
myservo.attach(9);
}

void loop() {
myservo.write(1 ,100, true);
myservo.write(5, 1, true);
myservo.write(10, 5, true);
myservo.write(15, 10, true);
myservo.write(20, 15, true);
myservo.write(25, 20, true);
myservo.write(30, 25, true);
myservo.write(35, 30, true);
myservo.write(40, 35, true);
myservo.write(45, 40, true);
myservo.write(50, 45, true);
myservo.write(55, 50, true);
myservo.write(60, 45, true);
myservo.write(65, 40, true);
myservo.write(70, 35, true);
myservo.write(75, 30, true);
myservo.write(80, 25, true);
myservo.write(85, 20, true);
myservo.write(90, 15, true);
myservo.write(95, 10, true);
myservo.write(100, 5, true);

myservo.write(95, 10, true);
myservo.write(90, 15, true);
myservo.write(85, 20, true);
myservo.write(80, 25, true);
myservo.write(75, 30, true);
myservo.write(70, 35, true);
myservo.write(65, 40, true);
myservo.write(60, 45, true);
myservo.write(55, 50, true);
myservo.write(50, 45, true);
myservo.write(45, 40, true);
myservo.write(40, 35, true);
myservo.write(35, 30, true);
myservo.write(30, 25, true);
myservo.write(25, 20, true);
myservo.write(20, 15, true);
myservo.write(15, 10, true);
myservo.write(10, 5, true);

}

can you help me ??? :frowning:

THANK YOU GUYS !!!!

Try adding some Delays, you could start using a 1000 milliseconds delay and see how it works, then try reducing it until it gets the smoothest.

Just add a:

delay(1000);

at the end of every end of position.

Good luck!

If you want simple harmonic motion why not code it:

#include <Servo.h>
Servo myservo;

void setup() 
{
  myservo.attach(9); 
}

void loop ()
{
  myservo.write (50 * (1 - cos(0.002 * millis()))) ;
}

Hi

Thank you so much for the help.
The code works, but i have this small delay at the end of the move again.
Check the video.

video - servo - delay

It should restart without this small break :frowning:

Do you have an idea how it works without this delay?

Thank you !!!

david_germany:
Do you have an idea how it works without this delay?

Use a different (smaller) value than "0.002".

No, that's not it, its the range of movement, not the period, that's an issue. The servo is hitting the end-stop
at one end of travel - its necessary to find the range of input values it can handle and stick to it.

Yes i had try it. It doesnt work.
:frowning:

Damnit

Hi,
What are you using as the servo power supply?
Hopefully not the 5V from the arduino.

Tom... :slight_smile:

yes. i´m using the 5v of the arduino.
it´s declared in my starter kit...
i should use the 5v power of the arduino...

why not ?

Hi,
The servos draw relatively high currents when they start to move, this will cause a drop in the 5V supply, this is not good for the onboard regulator and can cause the arduino to reset, the volt drop will mean that the servo is also not powered properly and it will stutter.

You can use 4 x AA batteries in series for the servo supply, but keep the servo gnd and the arduino gnd connected together so the control signal will still control the servo.

Tom..... :slight_smile:

great !!!! thank you tom.
ill try this :slight_smile:

hope it works...