loading

Help wiring and programming a Robot Arm?

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.

sort by: active | newest | oldest
Start with your power connections. DON'T run the servos via your Arduino, you'll burn it out.
martzsam (author)  steveastrouk4 years ago
That is what I was thinking. Did I wire it correctly for the power?
Looks OK
martzsam (author)  steveastrouk4 years ago
I have it wired up now and when I turn it on it just seizures.
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 ?
martzsam (author)  steveastrouk4 years ago
#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);
}
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.
martzsam (author)  steveastrouk4 years ago
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
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;


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

void loop()
{

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);
}

martzsam (author)  steveastrouk4 years ago
Ok this works. I have control and everything is responding. However It has a severe twitching problem.
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.
martzsam (author)  steveastrouk4 years ago
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...
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.
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
martzsam (author)  spiffomatic644 years ago
Well the servo knob example is only for one servo. I tried modifying and all it does it seizures.
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 ?
martzsam (author)  steveastrouk4 years ago
The bot is apparently only taking input from the A1 pot, and assigning that to all of the servos.
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.
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