Noisy Analog servo when in delay

Hello,
i am a newbie in this forum and with arduino, and a visual artist interested in various practices like electronics.
I am trying to use the sweep example in arduino software to move my hitec HS805BB in a specific way.
I want it to go to 0 degree from 180 and immediately back to 0 degree then wait ( for some unspecified time)
the code here below it doesn’t stop the servo, it just slow it.

// Sweep
// by BARRAGAN http://barraganstudio.com
// This example code is in the public domain.

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

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>=1; 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
}
}

Can someone lend me an hand?

Try something like this for the loop, and play with the #define’d values to change speeds and wait period?

#define FORWARD_SWEEP 3000
#define BACKWARD_SWEEP 1500
#define WAIT  4000

#define START_POS 0
#define END_POS 180
#define STEPS (END_POS-START_POS)


void loop()
{ 
  int forw_del = FORWARD_SWEEP / STEPS ;
  int back_del = BACKWARD_SWEEP / STEPS ;
  for (int pos = START_POS; pos <= END_POS; pos += 1)  // forwards loop
  {                                  // in steps of 1 degree
    myservo.write(pos); 
    delay(forw_del);
  } 
  for (int pos = END_POS; pos>=START_POS; pos-=1) // backwards loop
  {                                
    myservo.write(pos); 
    delay(back_del); 
  } 
  delay (WAIT) ;
}

the code here below it doesn’t stop the servo, it just slow it.

You have to remember that “loop” loops.
As soon as it has run once, it gets run again.

 for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 179 degrees 
  {                                  
    myservo.write(pos);
    delay(15);
  } 
  for(pos = 180; pos>=1; 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 
  }

I am learning that define can be very useful, i just try to compile Mark's code but i get this error:

sweep4.cpp: In function ‘void loop()’: sweep4.cpp:18: erreur: ‘myservo’ was not declared in this scope sweep4.cpp:23: erreur: ‘myservo’ was not declared in this scope

Tomorrow i will try to catch the problem, it seems i have forgotten the void setup or am i wrong? Good night, hope to see many replies at my wake-up.

Ok, i got it work, now i am trying to understand why it is noisy when it waits. Also if i can just use the pin 9 on the yellow wire to activate the servo and let the red and the black wire connected to the converter(1200 mA). Arduino does not deliver more than 40mA?
Trying to use that code, but i got errors:

#include <Servo.h>
#define FORWARD_SWEEP 2400
#define BACKWARD_SWEEP 540
#define WAIT 4000

#define START_POS 0
#define END_POS 180
#define STEPS (END_POS-START_POS)
pinMode(13,OUTPUT);

Servo myservo;

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

void loop()
{
int forw_del = FORWARD_SWEEP / STEPS ;
int back_del = BACKWARD_SWEEP / STEPS ;
for (int pos = START_POS; pos <= END_POS; pos += 1) // forwards loop
{ // in steps of 1 degree
myservo.write(pos);
delay(5);
}
for (int pos = END_POS; pos>=START_POS; pos-=1) // backwards loop
{
myservo.write(pos);
delay(5);
}
digitalWrite(13,LOW);
delay(WAIT);
digitalWrite(13,HIGH);
}

Ok, now it works, but i still have the same problem when the servo waits, it buzzes, it doesn't if i unplug the signal wire. My question is what it happens when i use the servo library? Am i supposed to modify the minimal pulse to adapt it to my specific servo? When the code says Delay does it means that pwm is still sending pulse to hold position? A command like myservo.detach can help me? Or should i rather use a transistor circuit to stop the motor red wire (load)? I tried this solution also and it works, but is a pretty ugly way and i would prefer to solve the problem inside the code.

Please use the # button when posting code.

When the code says Delay does it means that pwm is still sending pulse to hold position?

Yes.

If the servo is noisy when holding a fixed position then it normally is the servo that is the problem rather than the software or the signal feeding it.

i have two same servos and it's the same problem. Other idea?

You could check the PPM signal for jitter with a scope.