Go Down

Topic: Servo vibrates (Read 2 times) previous topic - next topic

kiriti

hey guys i connected the servo and everything works fine including the sweep

but when i use this code to read input from switch and then sweep servo it vibrates

Code: [Select]
#include <Servo.h>
int switchpin=7; //Input From button
Servo myservo;
int pos=1;
int value;
void setup()
{
  pinMode(switchpin, INPUT);
  myservo.attach(9);
  Serial.begin(9600);
}
void loop()
{
  value=digitalRead(switchpin);
  Serial.println(value);
  if(value==1)
  {
    for(pos = 1; pos < 45; pos += 1)
  {                                 
    myservo.write(pos);             
    delay(35);                     
  }
  for(pos = 45; pos>1; pos-=1) 
  {                               
    myservo.write(pos);           
    delay(1);                       
  }
  }
}


is it because of coding error or the signal wire being lose??

kiriti

i dont understand it, it acts wiered sometimes it works sometimes it doesnot, it vibrates sometimes :(

zoomkat

You probably need to explain how your servo is connected to the arduino, how you are powering the servo, and just what your code is supposed to do.
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

kiriti

i connected it using the arduino power supply

the 5v and the ground pins on the arduino to the servo and the signal to the pin 9



and my code just reads an input from pin 7 and executes it executes sweep once.... and yeah input is working fine ive checked the input readings on serial monitor using println function:)


yeah so powering it i am doing it directly from arduino connected to pc via usb, and when ever i connect the servo the device unmounts itself from windows and device goes into unrecognized and yeah servo works fine with normal sweep but doesnot with my code in which i just pasted the sweep code  into the if loop


cr0sh


i connected it using the arduino power supply

the 5v and the ground pins on the arduino to the servo and the signal to the pin 9



and my code just reads an input from pin 7 and executes it executes sweep once.... and yeah input is working fine ive checked the input readings on serial monitor using println function:)


yeah so powering it i am doing it directly from arduino connected to pc via usb, and when ever i connect the servo the device unmounts itself from windows and device goes into unrecognized and yeah servo works fine with normal sweep but doesnot with my code in which i just pasted the sweep code  into the if loop




Always, always use an external power supply for a servo; servos can easily overload the Arduino's voltage reg output, causing power sags and resets, etc. Put an external supply on the servo (and tie the grounds together). If you still run into problems, post your schematic and code, please!
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

potus98

Hi Kiriti,

I experienced a similar problem when I was building project CIRC-04 from the SparkFun Inventor's Kit. The example code provided with the SparkFun Inventor's Guide is very similar to your code sample so I suspect you might be performing the same project.

Although the documentation said the servo supports positions 0 through 180, it seems that positions 1 thru 14 are actually reserved for continuous rotation at different fixed speeds. 1 is fast. 2 is slightly slower. Approaching 14 gets slower and slower.

This means I had to limit my range of motion to positions 15-180. When I adjusted the code to only rotate the server to positions within this range, it worked fine.

If I wanted to watch the servo slowly spin non-stop, I could instruct the servo to seek position 14 and watch it turn slowly. For more excitement, I could instruct the servo to seek position 1 and watch it spin faster. Fun stuff! :-)

I suspect different servos could have different properties. The servo included in my kit was labeled "Micro Servo 9g A0090". If your servo is different, you might try stepping through various target positions to isolate which values provide the continuous rotation feature.

Hope this helps,
-John

wmeister

i've just started messing around with servos

as far as i can see, driving the servo beyond its physical limits will cause the vibrating

i discovered when using the sweep programme that i needed to make the limits between 30 and 170 degrees before the servo would stop chattering


dokb

I want to just support the answers listed here already. When the servo is near 0 or 180, there is vibration. I keep the values around 20-150 (which is all that I need) and the servo is perfectly still when holding those positions. Experiment maybe with the kind of servo you have.... mine are Hitec HS-81 micros.

Go Up