Pages: [1]   Go Down
Author Topic: Servo Help!! Urgent.  (Read 435 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ()

{
  myservo.attach(52);
  myservo2.attach(47);
  myservo3.attach(42);
  myservo4.attach(37);
 
}

void loop()

{
 

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

Hillsboro, OR
Offline Offline
Jr. Member
**
Karma: 1
Posts: 73
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"Beer is proof that god loves us and wants us happy" - a popular misquote of Benjamin Franklin, but true nonetheless.

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3080
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Full Member
***
Karma: 0
Posts: 240
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9698
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

UK
Offline Offline
Tesla Member
***
Karma: 135
Posts: 7757
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).

...R
Logged

Pages: [1]   Go Up
Jump to: