Go Down

Topic: My Servo vibrates rapidly. (Read 190 times) previous topic - next topic

Ralphie

The servo (Futaba S3003) that I am using for my project sometimes vibrates rapidly after it has finished rotating. I have to give it a little push with my finger to get it to stop, which sort of defeats the purpose of the whole project because my project was simply to control a servo remotely using two buttons, one to rotate clockwise 90 degrees, and the other button to rotate 90 degrees anticlockwise.

I thought it may have because both of my if statements are inside the void loop (), so they could be repeatedly running. To fix this I created a variable called limiter, to make sure no same rotation could happen twice in a row.

Is it possible to do what I've done below or am I missing something?

I declared "int limiter = 1;" in void setup ()

Code: [Select]


void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

if (buttonState == HIGH && limiter == 1) {     
    // rotate clockwise   
    myservo.writeMicroseconds(1800); 
    limiter = 2;
  }

  if (buttonState != HIGH && limiter == 2) {
    // rotate anticlockwise
    myservo.writeMicroseconds(1200);
    limiter = 1;
}
}



I really hope there's a problem somewhere there (there's definitely no problem elsewhere) because I don't want to have to buy a bloody servo again, it takes ages to deliver too.  :0 Cheers  :smiley-red:

jremington

Hopefully you are not attempting to power the servo from the Arduino. If so, don't. Use a separate power supply and connect the  grounds together.

polymorph

I second what jremington said, plus make sure you are using bypass capacitors on both power supplies.
Steve Greenfield AE7HD
Nick Gammon on multitasking Arduinos:
http://gammon.com.au/blink
http://gammon.com.au/serial
http://gammon.com.au/interrupts

zoomkat

Quote
my project was simply to control a servo remotely using two buttons, one to rotate clockwise 90 degrees, and the other button to rotate 90 degrees anticlockwise.


Two button servo code.

Code: [Select]

//zoomkat servo button test 12-29-2011
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int button2 = 5; //button pin, connect to ground to move servo
int press2 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(170);
  }   
 
  press2 = digitalRead(button2);
  if (press2 == LOW)
  {
    servo1.write(10);
  }
}

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Go Up