VEX Servo vibrating problem

I'm trying to turn my light switch on and off with a VEX Servo I picked up (got it free from my school). It's a 3 wire servo, here's more info: http://www.vexrobotics.com/products/accessories/motion/276-2162.html

I connected the black wire to ground, orange to +5V, and white to digital pin 9 (PWM). The servo turns fine but constantly vibrates and is noisy. Is there a way I can fix this? If not, what type of servo should I buy that is quite, and only makes a noise when it turns. Since this is in my room, I don't want to sleep with a constant buzzing in my ear.

Thanks for the help

It could be the servo, but it could also be your program not sending out the correct signal often enough or not always sending the same pulse length when the servo should be static. If you use the servo library, that shouldn't be a problem, if you do the PWM on your own, it might be.

Korman

I hope you are using the servo library. The arduino's PWM is not what servos use.

Yes, I'm using the arduino servo library. This is the first time I'm using a servo. My setup includes two lasers and two photoresisters placed a few cm apart. Depending on which order they're triggered, they turn the servo. The problem is that when the servo is still, it vibrates and makes noises. If you could tell me how I can improve my code, please do.

#include <Servo.h> 
 
Servo servo;
int visitors = 0;  //counts visitors in the room
int inside = 0;   //Analog IN pin for inner laser
int outside = 1;  //Analog IN pin for outer laser
int inner = 0;   //Inner photoresistor reading
int outer = 0;   //Outer photoresistor reading

void setup()
{
  Serial.begin(9600);
  servo.attach(9);
}

void loop()
{
inner = analogRead(inside);
outer = analogRead(outside);

//If inner laser is tripped,
if (inner < 800)
{
//keep checking for half a second
  for (int i = 0; i < 500; i++)
  {
    //then if outer laser is tripped,
    
    if (outer < 500) //(this value is 500 because this photoresistor is normally lower for some reason compared to the other one
    {
      //a person left the room
      visitors--;
      break;
    }
  }
}

//does the opposite of previous if statement
if (outer < 800)
{
  for (int i = 0; i< 500; i++)
  {
    if(inner < 500)
    {
      visitors++;
      break;
    }
  }
}

if (visitors > 0)
{
  servo.write(180);
}
else
{
  servo.write(0);
}
delay(500);
}

If you're not moving the servo for long periods of time, you could call "detach".
This will stop servo control pulses, so if it still vibrates, it isn't a problem with the library.

Okay I think detach(); works, but if I want to use the servo again, do I just say "attach(9)" in the loop function?

Ah I think I see the problem here. To test the servo I was using the following code

myservo.write(0);
delay(5000);
myservo.write(180);
delay(5000);

It vibrates during the "delay". Is that a thing with servos?

I connected the black wire to ground, orange to +5V

I hope that isn't to the +5v on the arduino board. It gets posted probably once a day in the forum that the arduino power supply is generally not adequate to power a servo.

Mine will vibrate at 180, but not at 177 or less degrees.

Mine will vibrate at 180, but not at 177 or less degrees.

It may be against the internal stop tab at 180 deg, which may cause it to get hot and use a lot of power.

Just a thought.. don't know if it is pertinent or not.. just a noobie with Arduino (using a 328). Be sure and look at the warning on using delay() (it prevents other processing while waiting) as opposed to using millis() and doing a do loop to wait for the elapsed time desired. -- good luck