Go Down

Topic: Servo Help!! Urgent. (Read 874 times) previous topic - next topic


Hello all,

     Me and my friend are attempting to build a robotic arm. We have 4 main servos which when attached to the power source (6v-7.5 amp) twitch violently back and forth. We've messed with the code, and even tried attaching it to arduino power itself but they dont seem to work correctly. Code:

#include <Servo.h>

Servo myservo;
Servo myservo2;
Servo myservo3;
Servo myservo4;

int potpin = 1;
int potpin2 = 2;
int potpin3 = 3;
int potpin4 = 4;

int val = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;

void setup ()


void loop()


  val = analogRead(potpin);
  val = map(val, 0, 1023, 0, 179);
  val2 = analogRead(potpin2);
  val2 = map(val2, 0, 1023, 0, 179);
  val3 = analogRead(potpin3);
  val3 = map(val3, 0, 1023, 0, 179);
  val4 = analogRead(potpin4);
  val4 = map(val4, 0, 1023, 0, 179);
Hopefully someone out there could help us out with debugging this thing, need answers asap since we're hard pressed for time.


What board are you using?

When the servos are connected to a separate power source, are the arduino and power sources grounds connected?

Also, please use code tags when posting code.
"Beer is proof that god loves us and wants us happy" - a popular misquote of Benjamin Franklin, but true nonetheless.


I suggest you check whether your servos are actually capable of 180 degrees of movement,  most of them are not.


Try a capacitor! I have a 25v 2200uf cap on my robotic arm. It takes a lot of twitch out. Had the exact same thing happen to me. And you HAVE TO ground to a common source. All of my servo grounds, and external grounds go to the arduino. If you don't, it will not work well, if at all.


You may have too much load on the servos and they are hunting. Do the servos twitch when they are not loaded? If only one servo is being powered and the rest disconnected, does the connected servo still twitch?
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0


Yesterday I discovered (based on something I read on another forum) that putting a resistor from the signal to the ground connection of the servo (which holds the signal low) has stopped it acting wildly when there is no signal applied. I've used a 4k7 resistor. If that doesn't work it might be worth putting the resistor between signal and power (i.e. holding the signal line high).

Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up