Desperate need of help with robotic arm

We are 2 high school students struggling with a robotic arm project for our engineering class. We have a 4-axis sainsmart robotic arm ( http://www.sainsmart.com/diy-4-axis-servos-control-palletizing-robot-arm-model-for-arduino-uno-mega2560.html ) and after months of searching the internet for code to control it with a joystick we have found nothing.
We simply dont know what kind of joystick to get, and have NO knowledge of how to code. If someone has a code or has any expierence with this project, that would be greatly appreciated. Thanks!

(deleted)

This isn't homework, we've been working on this for 4 months and need help. We've reached a dead end through our research online and hope someone has some experience with this who can help

This is a nice arm with 4 motors. Do you have any code to run servo motors? What code have you tried?

Googling "arduino joystick" turns up lots of ideas for wiring and code, for example this first hit.

Which have you tried and what happened?

Did you try the example code from www.sainsmart.com?

// Example code from www.sainsmart.com
#include <Servo.h>

long Joystick_1_X;
long Joystick_1_Y;
long Joystick_2_X;
long Joystick_2_Y;
long Joystick_1;
long Joystick_2;


Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

float k_1;
float k_2;
float k_3;
float k_4;

float speed_1;
float speed_2;
float speed_3;
float speed_4;

void setup(){
  Serial.begin(115200);

  servo1.attach(5);
  servo2.attach(6);
  servo3.attach(9);
  servo4.attach(10);

}

void loop(){
  Joystick_1_X = analogRead(A0);
  Joystick_1_Y = analogRead(A1);
  Joystick_2_X = analogRead(A2);
  Joystick_2_Y = analogRead(A3);

  if(Joystick_1_X > 530){
    k_1 = map(Joystick_1_X, 531, 1023, 0, 100) / 2000.00;
  }
  else if(Joystick_1_X < 470){
    k_1 = map(Joystick_1_X, 0, 469, -100, 0) / 2000.00;
  }
  else{
    k_1 = 0;
  }

  if(Joystick_1_Y > 530){
    k_2 = map(Joystick_1_Y, 531, 1023, 0, 100) / 2000.00;
  }
  else if(Joystick_1_Y < 470){
    k_2 = map(Joystick_1_Y, 0, 469, -100, 0) / 2000.00;
  }
  else{
    k_2 = 0;
  }

  if(Joystick_2_X > 530){
    k_3 = map(Joystick_2_X, 531, 1023, 0, 100) / 2000.00;
  }
  else if(Joystick_2_X < 470){
    k_3 = map(Joystick_2_X, 0, 469, -100, 0) / 2000.00;
  }
  else{
    k_3 = 0;
  }

  if(Joystick_2_Y > 530){
    k_4 = map(Joystick_2_Y, 531, 1023, 0, 100) / 2000.00;
  }
  else if(Joystick_2_Y < 470){
    k_4 = map(Joystick_2_Y, 0, 469, -100, 0) / 2000.00;
  }
  else{
    k_4 = 0;
  }

  speed_1 = min(60, max(-60, speed_1 += k_1));
  speed_2 = min(35, max(-35, speed_2 += k_2));
  speed_3 = min(35, max(-35, speed_3 += k_3));
  speed_4 = min(35, max(-35, speed_4 += k_4));

  Serial.print("  k_1="); 
  Serial.print(k_1);
  Serial.print("  k_2="); 
  Serial.print(k_2);
  Serial.print("  k_3="); 
  Serial.print(k_3);
  Serial.print("  k_4="); 
  Serial.println(k_4);

  servo1.write(speed_1 + 90);
  servo2.write(speed_2 + 90);
  servo3.write(speed_3 + 90);
  servo4.write(speed_4 + 90);
}

Edit:

You connect your Servo like these to pins D5,D6,D9,D10
servo power.jpg

You connect your Joystick like this, to A0, A1, A2, A3, total two joystick needed.

You can use Joystick module like this

You could start with simple joystick modules like below or pots like bottom. Bottom code is some pot that has been posted in the forum.

http://www.ebay.com/itm/3D-Controller-Joystick-Axis-Analog-Sensor-Module-Replacement-Part-for-Xbox360-GL-/121846182105?hash=item1c5e9930d9:g:MEcAAOSwk1JWePgs

http://www.ebay.com/itm/10x-B10K-Ohm-Linear-Taper-Rotary-Potentiometer-Panel-Pot-15mm-Shaft-Nuts-Washers-/291010300828?hash=item43c190cb9c:g:BEUAAMXQWzNSeSs6

#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;

int DefPos1, DefPos2;

int potpin1 = 0;
int potpin2 = 1;
int potpin3 = 2;
int potpin4 = 3;
int potpin5 = 4;
int potpin6 = 5;

int val1;
int val2;
int val3;
int val4;
int val5;
int val6;


void setup() {
 servo1.attach(2);
 servo2.attach(3);
 servo3.attach(4);
 servo4.attach(5);
 servo5.attach(6);
 servo6.attach(7);

 servo1.write(130); // Place default positions
 servo2.write(90);
 servo3.write(70);
 servo4.write(50);
 servo5.write(80);
 servo6.write(110);
}


void loop() {

 val1 = analogRead(potpin1);
 val1 = map(val1, 80, 1024, 0, 180);
 servo1.write(val1);

 val2 = analogRead(potpin2);
 val2 = map(val2, 20, 1024, 0, 150);
 servo2.write(val2);

 val3 = analogRead(potpin3);
 val3 = map(val3, 20, 1024, 0, 120);
 servo3.write(val3);

 val4 = analogRead(potpin4);
 val4 = map(val4, 20, 1024, 0, 90);
 servo4.write(val4);

 val5 = analogRead(potpin5);
 val5 = map(val5, 10, 1024, 0, 170);
 servo5.write(val5);

 val6 = analogRead(potpin6);
 val6 = map(val6, 50, 1024, 0, 120);
 servo6.write(val6);

 delay(50);
}

Thanks for your support guys, Still having issues, our arm twitches whenever we find a code, we are using a wall power supply with 9v, we think we may need to up the power, but dont know. We currently don't have any joysticks, and are probably going to order a couple of these http://www.amazon.com/SainSmart-JoyStick-Breakout-Module-Arduino/dp/B00CO2N18A/ref=sr_1_1?ie=UTF8&qid=1455739343&sr=8-1&keywords=joystick+arduino We don't have enough time to learn how to code because the project is due in about a month. The company sent us some tutorial videso after contacting them, and we are going to try to upload them ASAP. Thanks

You said you have a 9V wall supply but you didn't say how the servos are powered. In #5 BillHo shows how the servos must be connected: they need their own supply so I hope you aren't powering them from the Arduino's 5V. (Nice pic Bill :wink: ) I'm hoping the 9V is merely for running the Arduino itself. (You can't put 9V into the servos, and the Arduino 5V isn't up to powering servos which need about 1 amp each.)

Did you power them from their own 5-6V supply? You MUST do that before you continue.