Society of Robots - Robot Forum

Mechanics and Construction => Mechanics and Construction => Topic started by: jsaginaw14 on February 17, 2013, 02:32:54 PM

Title: Robotic Arm run by Arduino
Post by: jsaginaw14 on February 17, 2013, 02:32:54 PM
Hello,
My name is Joe and my friends and I are building a robotic arm for a competition.

We have constructed an arm that utilizes 6 servos for 5 joints, and a dc motor is used to turn the whole set up left and right. We are using an Arduino Mega 2560 and potentiometers to control each individual servo. The wiring is done through a breadboard. We have a 9 volt battery working the DC motor, a 6 volt battery giving power to the arduino board, and another 6 volt battery running the potentiometers.  There are two servos at the base joint, and one servo at all the other joints.  The servos are Standard servos from BP Hobbies and the baterris are 6 V, 1600maH, NiMH Tenergy batteries.  The potentiometers are 25-ohm potentiometers from RadioShack.  There is a knife switch controlling the direction of the DC motor and a 5K-ohm potentiometer controlling its speed. 

Everything is wired properly, we have checked numerous times and used an ohm meter.  Concerning the power sources, there are different ones.  The board and the servos are running off their own 6V battery, which is inputted into the board with a spliced DC jack plug going into the DC  jack on the arduino board.  The other ends are attached to the battery leads.  The servos are getting power through the 5V pin and grounded to the GND pin.  They get their signal from the PWM outputs on the board.     

The potentiometers have a very low ohm-rating, so we put them on a separate circuit because they use alot of current.  Their positive and ground ends are attached to another 6V battery, and the output wires from the center of the potentiometer go into the analog input pins of the arduino board. 

Here is an example of the code:
#include <Servo.h>
 
Servo myservo;
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
 
int potpin = 0;
int potpin1 = 1;
int potpin2 = 2;
int potpin3 = 3;
int potpin4 = 4;

int val;
int val1;
int val2;
int val3;
int val4;
void setup()
{
  myservo.attach(9);
  myservo1.attach(8);
  myservo2.attach(7);
  myservo3.attach(6);
  myservo4.attach(5);
}
 
void loop()
{
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(30);                           // waits for the servo to get there
 
  val1 = analogRead(potpin1);           
  val1 = map(val1, 0, 1023, 0, 179);     
  myservo1.write(val1);                 
  delay(30);                         

  val2 = analogRead(potpin2);           
  val2 = map(val2, 0, 1023, 0, 179);     
  myservo2.write(val2);                   
  delay(30);                           

  val3 = analogRead(potpin3);           
  val3 = map(val3, 0, 1023, 0, 179);     
  myservo3.write(val3);                 
  delay(30);                           

  val4 = analogRead(potpin4);           
  val4 = map(val4, 0, 1023, 0, 179);     
  myservo4.write(val4);                 
  delay(30);                           
}

When we have everything hooked up, the arm start going nuts and moves like it has a mind of its own. We do have some control over it, but the arm is still jerking left and right at almost every joint, the most at the servo controlling the gripper.  We have ruled out noise interference because we have had complete-non jerky control over it at previous points in time. 

The competition is next weekend so please help.   :)
If you need pictures, I will zip them and attach them but they are too large to attach at the moment
Title: Re: Robotic Arm run by Arduino
Post by: jwatte on February 17, 2013, 11:22:00 PM
Some things:

1) Get new potentiometers. A 5k or 10k potentiometer will be plenty for the Arduino input, and will not burn off all your power.

2) Make sure that the "-" contacts for ALL THE BATTERIES are connected together. This creates a common ground. Else you'll have who-knows-what kind of problems.

3) What powers the servos? Each servo may need 1A of current. If you're trying to power the servos using the same battery as the Arduino, that would cause problems when the voltage drops and the Arduino resets.

4) You are calling delay() after each servo write. You do not need to do this. The servo library will generate the right pulses at the right times; your control of the servo library just tells it what those pulses should be when the time comes around. (It keeps doing this forever)

5) You should put something like "flash a LED for 5 seconds" in the setup() function. This will let you know when the Arduino resets.

Code: [Select]
void setup() {
  pinMode(13, OUTPUT); // the built-in LED on Arduino UNO
  for (int i = 0; i < 25; ++i) {
    digitalWrite(13, HIGH);
    delay(50);
    digitalWrite(13, LOW);
    delay(50);
  }
  ... do other setup
}


6) You should also reduce everything to the simplest possible setup. Start with only a single servo, nothing else hooked up. Make sure that works. Then expand to two servos. Repeat...
Title: Re: Robotic Arm run by Arduino
Post by: Azraels on February 18, 2013, 04:36:52 PM
I remember having the same jerky movements in my servos on the first arm I built. It was more than likely caused by not having everything running to the same ground including the arduino ground on the digital I/O pin line. But before I had figured that out I had put it down to the pots not keeping a constant value at a certain position causing the map to be constantly changing the servo's position. I rewrote the code to increment write values to the servos when the pot was greater than or less than a certain middle stop value.
Title: Re: Robotic Arm run by Arduino
Post by: jsaginaw14 on February 18, 2013, 07:20:12 PM
Thank you guys so much.  I will definitely try these potential solutions out. I have also heard that twisting the signla wires can reduce noise interference, but I believe there is too much jittering to be just noise.  Currently, I have the potentiometers and the board on the same 6V battery and the motors on their separate battery.  Would it be possible to run everything through the board with 2-3 6V batteries in parallel to provide 6V but 3200-4800maH through the board to power everything so they are all grounded to GND?

Thanks so much again.
Joe   
Title: Re: Robotic Arm run by Arduino
Post by: Azraels on February 18, 2013, 07:44:42 PM
Well you could, but remember the recommended voltage for the Mega is 7 to 12 volts and you are at the minimum of 6v. Any sudden loss of voltage can cause the Arduino to reset, which could happen when your motors kick on. You might want to try a higher voltage battery. And you can still use different voltage batteries like you were before just link there negatives.
Title: Re: Robotic Arm run by Arduino
Post by: ben23f on February 19, 2013, 10:38:21 PM
I have made a couple projects using Arduino and Servos and always it has played up (even killing an Arduino) without a direct power supply to the servos. They wont run properly off the Arduinos 5V as it wont give enough current.
This was with Arduino unos anyway but should be the same idea?
Title: Re: Robotic Arm run by Arduino
Post by: Azraels on February 20, 2013, 12:28:11 PM
yeah I dont think he was running all those servos off the arduino's 5v pin, that would be bad. He was going to run the arduino and servo's off the same 6v line, which I do not think would have worked well.
Title: Re: Robotic Arm run by Arduino
Post by: jwatte on February 20, 2013, 12:31:48 PM
Feeding 6V to the "Vin" on the Arduino is definitely very marginal, because the Arduino uses a crappy high-drop-out regulator instead of an ultra-low-drop-out regulator that would let it accept 5.5V in. I'm sure they saved all of ten cents per board because of this :-/

As long as you connect all the "-" poles of all the batteries together somehow, the exact configuration can change. It's often a good idea to power the servos directly from a battery "+" pole to make sure they can get plenty of current. The two options you're suggesting are about equal -- I'd prefer the two parallel batteries.

The dashed line indicates the difference between the two modes of parallel vs separate batteries. Note the important connection!

(http://watte.net/batteries.png)