1748Views20Replies

Author Options:

Help wiring and programming a Robot Arm? Answered

Picture of

I have been building a robot arm for a competition, and I have the structure completed. I am very new to Arduino, and have little know-how when it comes to wiring properly and even less when it comes to programming. I have uploaded pictures of the robot arm as well as a crude circuit diagram of what I think needs to be wired. (Sorry if it is a bit confusing, I am reaaaaally new to this.) I am trying to control each joint (claw, wrist, elbow, shoulder, and rotary base) with a 10k pot. similar to how the Arduino servo knob command works. I plan on eventually making an instructable for this and will credit any help I get there.

21 Replies

user
steveastroukBest Answer (author)2013-02-03

Start with your power connections. DON'T run the servos via your Arduino, you'll burn it out.

Select as Best AnswerUndo Best Answer

user
martzsam (author)steveastrouk2013-02-03

That is what I was thinking. Did I wire it correctly for the power?

Select as Best AnswerUndo Best Answer

user
martzsam (author)steveastrouk2013-02-03

I have it wired up now and when I turn it on it just seizures.

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)martzsam2013-02-03

Take off all but one servo, get that running. I'm not pretending to read the "drawing" of what you have. I might read a circuit diagram.

What code have you loaded on the Arduino ?

Select as Best AnswerUndo Best Answer

user
martzsam (author)steveastrouk2013-02-03

#include

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

int potpin = 1;
int potpin2 = 2;
int potpin3 = 3;
int potpin4 = 4;
int potpin5 = 5;
int val;
int val2;
int val3;
int val4;
int val5;

void setup()
{
myservo.attach(1);
myservo2.attach(2);
myservo3.attach(3);
myservo4.attach(4);
myservo5.attach(5);
}

void loop()
{
val = analogRead(potpin);
val2 = analogRead(potpin2);
val3 = analogRead(potpin3);
val4 = analogRead(potpin4);
val5 = analogRead(potpin5);
val = map(val, 0, 1023, 0, 179);
val2 = map(val, 0, 1023, 0, 179);
val3 = map(val, 0, 1023, 0, 179);
val4 = map(val, 0, 1023, 0, 179);
val5 = map(val, 0, 1023, 0, 179);
myservo.write(val);
myservo2.write(val2);
myservo3.write(val3);
myservo4.write(val4);
myservo5.write(val5);

delay(15);
}

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)martzsam2013-02-03

Your code around the map statements is wrong - but this is cleaner anyway:

myservo.write( map( analogRead (potpin),0,1023,0,178));
myservo2.write( map( analogRead (potpin2),0,1023,0,178));
myservo3.write( map( analogRead (potpin3),0,1023,0,178));
//saves variables and code.

Select as Best AnswerUndo Best Answer

user
martzsam (author)steveastrouk2013-02-03

Ok I tried this:

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

int potpin = 1;
int potpin2 = 2;
int potpin3 = 3;
int potpin4 = 4;
int potpin5 = 5;
int val;
int val2;
int val3;
int val4;
int val5;

void setup()
{
myservo.attach(1);
myservo2.attach(2);
myservo3.attach(3);
myservo4.attach(4);
myservo5.attach(5);
}

void loop()
{
val = analogRead(potpin);
val2 = analogRead(potpin2);
val3 = analogRead(potpin3);
val4 = analogRead(potpin4);
val5 = analogRead(potpin5);
val = map(val, 0, 1023, 0, 179);
val2 = map(val, 0, 1023, 0, 179);
val3 = map(val, 0, 1023, 0, 179);
val4 = map(val, 0, 1023, 0, 179);
val5 = map(val, 0, 1023, 0, 179);
myservo.write( map( analogRead (potpin),0,1023,0,178));
myservo2.write( map( analogRead (potpin2),0,1023,0,178));
myservo3.write( map( analogRead (potpin3),0,1023,0,178));
//saves variables and code.

delay(15);
}

But I got this:

sketch_feb03a:1: error: 'Servo' does not name a type
sketch_feb03a:2: error: 'Servo' does not name a type
sketch_feb03a:3: error: 'Servo' does not name a type
sketch_feb03a:4: error: 'Servo' does not name a type
sketch_feb03a:5: error: 'Servo' does not name a type
sketch_feb03a.ino: In function 'void setup()':
sketch_feb03a:20: error: 'myservo' was not declared in this scope
sketch_feb03a:21: error: 'myservo2' was not declared in this scope
sketch_feb03a:22: error: 'myservo3' was not declared in this scope
sketch_feb03a:23: error: 'myservo4' was not declared in this scope
sketch_feb03a:24: error: 'myservo5' was not declared in this scope
sketch_feb03a.ino: In function 'void loop()':
sketch_feb03a:39: error: 'myservo' was not declared in this scope
sketch_feb03a:40: error: 'myservo2' was not declared in this scope
sketch_feb03a:41: error: 'myservo3' was not declared in this scope

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)martzsam2013-02-03
You've missed the library include, and the point of the code snippet I showed.

Steve

#include <Servo.h>

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

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


voidsetup()
{
myservo.attach(1);
myservo2.attach(2);
myservo3.attach(3);
myservo4.attach(4);
myservo5.attach(5);
}

voidloop()
{

myservo.write( map( analogRead (potpin),0,1023,0,178));
myservo2.write( map( analogRead (potpin2),0,1023,0,178));
myservo3.write( map( analogRead (potpin3),0,1023,0,178));
myservo4.write( map( analogRead (potpin4),0,1023,0,178));
myservo5.write( map( analogRead (potpin5),0,1023,0,178));

//saves variables and code.delay(15);
}

Select as Best AnswerUndo Best Answer

user
martzsam (author)steveastrouk2013-02-03

Ok this works. I have control and everything is responding. However It has a severe twitching problem.

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)2013-02-04

You might get better results by driving the pots from the REGULATED supply from the Arduino. I think you might be able to pick it off Vref too. DO NOT put anything BUT the pots on that pin.

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)martzsam2013-02-03

Increase your delay time to say 100 for a start. You'll probably find you have very noisy data from your pots. You should check that by using the serial port to print the read-back number from the pots.

You could filter the signal digitally, but that's a topic for another day.

Select as Best AnswerUndo Best Answer

user
martzsam (author)steveastrouk2013-02-03

Would I be better off if I bought higher quality pots? I have increased the delay to 500 and it is doing things on its own...

Select as Best AnswerUndo Best Answer

user
spiffomatic64 (author)2013-02-03

your diagram looks fine, just replicate the servo pot example like you said here http://arduino.cc/en/Tutorial/Knob and change the pins, and it should work fine

Select as Best AnswerUndo Best Answer

user
martzsam (author)spiffomatic642013-02-03

Well the servo knob example is only for one servo. I tried modifying and all it does it seizures.

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)martzsam2013-02-03

What do you mean by "seizures" ? Do you mean "seizes up", ie, twiddling the pots does nothing?

Are you getting a change in volts on the input to the Arduino AnalogIn pins ?

Select as Best AnswerUndo Best Answer

user
martzsam (author)steveastrouk2013-02-03

The bot is apparently only taking input from the A1 pot, and assigning that to all of the servos.

Select as Best AnswerUndo Best Answer

user
spiffomatic64 (author)martzsam2013-02-03

debug it a bit, take it down to just 2 servos, add some Serial.print's to verify the data before it hits the servo objects

Try moving the servo pins up past 0 and 1 (these are usually used by serial communication)

so have them start at 2 or so

Select as Best AnswerUndo Best Answer

user
martzsam (author)2013-02-03

I'm sorry I really have no idea how most of this works. I don't know what that means.

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)martzsam2013-02-03

Well yes, that's what I said in another comment here somewhere.

Compare my code with your code, and see if you can see your mistake.

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)martzsam2013-02-03

Then you hadn't actually tried the code you said you had before, because that had the same problem.
right at the TOP you should have
#include

Select as Best AnswerUndo Best Answer