Pages: [1]   Go Down
Author Topic: Servo Keep Twitching  (Read 306 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have purchased the starter kit from Vilros, I did every circuits until Servo project with Arduino Uno. I connected everything as the guide book said and opened the example code that goes along with the circuit. But for some reason my Servo keep twitching every second, imagine it sounds like a clock keep ticking, it rotated like 10 degrees at a time instead of 90 or 180. I bought another servo and the result is the same. Here is the code from the starter guide I bought:
Code:
/*

Example sketch 08

SINGLE SERVO

  Sweep a servo back and forth through its full range of motion.

  A "servo", short for servomotor, is a motor that includes
  feedback circuitry that allows it to be commanded to move to
  specific positions. This one is very small, but larger servos
  are used extensively in robotics to control mechanical arms,
  hands, etc. You could use it to make a (tiny) robot arm,
  aircraft control surface, or anywhere something needs to be
  moved to specific positions.

Hardware connections:

  The servo has a cable attached to it with three wires.
  Because the cable ends in a socket, you can use jumper wires
  to connect between the Arduino and the servo. Just plug the
  jumper wires directly into the socket.
  
  Connect the RED wire (power) to 5 Volts (5V)
  Connect the WHITE wire (signal) to digital pin 9
  Connect the BLACK wire (ground) to ground (GND)

  Note that servos can use a lot of power, which can cause your
  Arduino to reset or behave erratically. If you're using large
  servos or many of them, it's best to provide them with their
  own separate 5V supply. See this Arduino Forum thread for info:
  http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1239464763

This sketch was written by SparkFun Electronics,
with lots of help from the Arduino community.
This code is completely free for any use.
Visit http://www.arduino.cc to learn about the Arduino.

Version 2.0 6/2012 MDG
*/


// If we had to write a sketch to control a servo from scratch,
// it would be a lot of work. Fortunately, others have done the
// hard work for you. We're going to include a "library"
// that has the functions needed to drive servos.

// A library is an set of additional functions you can add to
// your sketch. Numerous libraries are available for many uses,
// see http://arduino.cc/en/Reference/Libraries for information
// on the standard libraries, and Google for others. When you're
// using a new part, chances are someone has written a library
// for it.

#include <Servo.h>  // servo library

// Once you "include" a library, you'll have access to those
// functions. You can find a list of the functions in the servo
// library at: http://arduino.cc/en/Reference/Servo
// Most libraries also have example sketches you can load from
// the "file/examples" menu.

// Now we'll create a servo "object", called myservo. You should
// create one of these for each servo you want to control.
// You can control a maximum of twelve servos on the Uno
// using this library. (Other servo libraries may let you
// control more). Note that this library disables PWM on
// pins 9 and 10!

Servo servo1;  // servo control object


void setup()
{
  // We'll now "attach" the servo1 object to digital pin 9.
  // If you want to control more than one servo, attach more
  // servo objects to the desired pins (must be digital).

  // Attach tells the Arduino to begin sending control signals
  // to the servo. Servos require a continuous stream of control
  // signals, even if you're not currently moving them.
  // While the servo is being controlled, it will hold its
  // current position with some force. If you ever want to
  // release the servo (allowing it to be turned by hand),
  // you can call servo1.detach().

  servo1.attach(9);
}


void loop()
{
  int position;
  
  // To control a servo, you give it the angle you'd like it
  // to turn to. Servos cannot turn a full 360 degrees, but you
  // can tell it to move anywhere between 0 and 180 degrees.

  // Change position at full speed:

  servo1.write(90);    // Tell servo to go to 90 degrees

  delay(3000);         // Pause to get it time to move

  servo1.write(180);   // Tell servo to go to 180 degrees

  delay(2000);         // Pause to get it time to move

  servo1.write(0);     // Tell servo to go to 0 degrees

  delay(1000);         // Pause to get it time to move
  
  // Change position at a slower speed:

  // To slow down the servo's motion, we'll use a for() loop
  // to give it a bunch of intermediate positions, with 20ms
  // delays between them. You can change the step size to make
  // the servo slow down or speed up. Note that the servo can't
  // move faster than its full speed, and you won't be able
  // to update it any faster than every 20ms.

  // Tell servo to go to 180 degrees, stepping by two degrees
 
  for(position = 0; position < 180; position += 2)
  {
    servo1.write(position);  // Move to next position
    delay(20);               // Short pause to allow it to move
  }

  // Tell servo to go to 0 degrees, stepping by one degree

  for(position = 180; position >= 0; position -= 1)
  {                                
    servo1.write(position);  // Move to next position
    delay(20);               // Short pause to allow it to move
  }
}
Please help!
« Last Edit: June 22, 2014, 02:54:26 am by PizzaPat » Logged

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 96
Posts: 4347
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I see the comments at the top of the code say you should perhaps NOT connect the servo to the Arduino's 5V. I'd try with its own supply, as shown attached. Make sure to connect the grounds.


* Many servos- small V2.jpg (11.94 KB, 320x180 - viewed 25 times.)
Logged

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I see the comments at the top of the code say you should perhaps NOT connect the servo to the Arduino's 5V. I'd try with its own supply, as shown attached. Make sure to connect the grounds.

Do you mean something like this diagram?
Logged

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 96
Posts: 4347
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep
Logged

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12179
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Allow at least 1A per small servo for the power supply.

95% or more of servo problems here are inadequate power.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was having the same issue, no real movement of the servo until I grounded the power supply to the Arduino.  Can you explain why this is needed?  Does this provide a loop back for the output from pin 9?

Also, I am not getting exact control.  When I say write(90), it goes further than 90, probably 100.  When I say write(180), the servo tries to go beyond 180 and sits there rattling!?

I am new to servo control and have Googled all over.  Any pointers to some good pointers is appreciated.

Thanks
Kevin
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was having the same issue, no real movement of the servo until I grounded the power supply to the Arduino.  Can you explain why this is needed?  Does this provide a loop back for the output from pin 9?

Correct, current onlly flows in a loop, so output pin, through servo control input pin, out servo ground, back to arduino ground.

Also, I am not getting exact control.  When I say write(90), it goes further than 90, probably 100.  When I say write(180), the servo tries to go beyond 180 and sits there rattling!?

 The servo library is a little brain dead as it makes assumptions about the specific servo you are using that may or may not be true. Not all servos can physical travel 180 degrees. A good way to test your specific servo's travel range is to use servo.writeMicroseconds(xxxx) command where xxxx = 1500 for the center of travel, xxxx = 1000  to 2000 is 'guaranteed' for most all servos but most have some under and over range that accounts for the total travel range possible before hitting mechanical stops on the gear train. The servo library assumes physical end points of 544 and 2400. Test for your end of ranges and you will know how many degrees are possible for your servo.

I am new to servo control and have Googled all over.  Any pointers to some good pointers is appreciated.

Thanks
Kevin
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I see the comments at the top of the code say you should perhaps NOT connect the servo to the Arduino's 5V. I'd try with its own supply, as shown attached. Make sure to connect the grounds.

Sorry for late reply, once you told me it needs its own power supply I immediately ordered it from Amazon. The result is successful! It works perfectly with the 6 Volts Servo on the 6 volts power supply. Thank you!
Logged

Pages: [1]   Go Up
Jump to: