How do i slow down my servo in my code

So first off I’m new to this and i don’t fully understand code and its in and outs but im sorta stuck and now really need some help.

so my problem is i have some code for my project what on press of a button changes the position of my servo from one point to another and apon a second press of the button it goes back to the first point and so on and so on, but as it is it moves way to fast for my linking and since this is for use in a helmet it currently throws the weight forward what its arm is attached.

so i just want to be able to slow it down so it still moves smoothly but also doesn’t try and lurch my forward.

Any help would be highly appreciated

#include <Servo.h>;

 
 // pushbutton pin
 const int buttonPin = 8;

 // servo pin
 const int servoPin = 3;
 Servo myservo;

 int pos = 0;

//create a variable to store a counter and set it to 0
int counter = 0;
void setup()
{
  myservo.attach (3);
  
  // Set up the pushbutton pins to be an input:
  pinMode(buttonPin, INPUT);
}


void loop()  {
  
 // local variable to hold the pushbutton states
  int buttonState;  

  //read the digital state of buttonPin with digitalRead() function and store the           //value in buttonState variable
  buttonState = digitalRead(buttonPin);

  //if the button is pressed increment counter and wait a tiny bit to give us some          //time to release the button
  if (buttonState == LOW) // light the LED
  {
    counter++;
    delay(100);
    
  }
  if(counter == 0)
    myservo.writeMicroseconds (1580);  // zero degrees
  else if(counter == 1)
    myservo.writeMicroseconds(0);
  
  //else reset the counter to 0 which resets thr servo to 0 degrees
  else
   counter = 0;
}

If you had posted your code properly I would be able to see it but I can't open attachments.

But generally if you use use VarSpeedServo.h instead of the normal Servo.h library it will let you specify the speed the servo moves.

Steve

Have a look at the Servo Sweep example in the IDE

slipstick:
If you had posted your code properly I would be able to see it but I can't open attachments.

But generally if you use use VarSpeedServo.h instead of the normal Servo.h library it will let you specify the speed the servo moves.

Steve

Thing is though i have tried using VarSpeedServo.h and i keep getting errors files are missing

Thing is though you have not posted any code or details of the errors

UKHeliBob:
Thing is though you have not posted any code or details of the errors

i have put the code up now and here is the errors

ERRORS:

Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:56:23: fatal error: WProgram.h: No such file or directory

Multiple libraries were found for "VarSpeedServo.h"
compilation terminated.

exit status 1
Error compiling for board Arduino Nano.

You have more than one copy of the VarSpeedServo library on your PC and one or more of them is very old.

I suggest that you delete all of the VarSpeedServo folders and install the library from GitHub - netlabtoolkit/VarSpeedServo: Arduino library for servos that extends the standard servo.h library with the ability to set speed, and wait for position to complete

That version of VarSpeedServo has been updated

From the .cpp file

#include <Arduino.h> // updated from WProgram.h to Arduino.h for Arduino 1.0+, pva

UKHeliBob:
You have more than one copy of the VarSpeedServo library on your PC and one or more of them is very old.

I suggest that you delete all of the VarSpeedServo folders and install the library from GitHub - netlabtoolkit/VarSpeedServo: Arduino library for servos that extends the standard servo.h library with the ability to set speed, and wait for position to complete

That version of VarSpeedServo has been updated

From the .cpp file

#include <Arduino.h> // updated from WProgram.h to Arduino.h for Arduino 1.0+, pva

Cheers the new file worked but now its how would i go about implementing the speed into my code?

Did you look at the examples with the library ?

Try looking at the examples that come with that library or even read the documentation on the page UKHeliBob pointed you to.

Steve

so give got it to work now with the speed but now its giggling alot when i put the weight of the 3D printed part on it

Overloaded servo, or inadequate servo power supply.

If you are trying to power the servo from the 5V Arduino output, that is the problem. Try a 4xAA battery pack and connect all the grounds.