Robotic Arm 4-Axis Problems

I am doing a high school engineering project with the Sainsmart 4 axis Robotic Arm. We bought it recently and have been trying to get it to work with an Arduino Mega 2560. So far, we believe we have set it up right, we are using a breadboard to connect the servos to the arduino. We were given a code by the manufacturer, that we've been trying to used in codebenders, but so far, the arm only twitches, and will sometimes extend itself all the way out, but not retract itself back or use any of the other 3 servos. We found more codes which do the same things, or flat out don't work. We dont know if we need more or less power, or if the codes we found are wrong, but so far nothing works. We are beginners and we don't understand coding, we've just tinkered with some of the numbers in the codes. If anyone has any tips or previous experiences with robotic arms, please help us out.
Below is a code found online that is supposed to work. Any ideas to why it's not? And what does it mean by joystick?

#include <Servo.h>

Servo panServo; // Create a servo object for the pan (horizontal) servo
Servo tiltServo; // Create a servo object for the tilt (vertical) servo
Servo zoomServo; // Create a servo object for zoom (left/right) servo
Servo downServo; // Create a servo obhect for record (down/up) servo

int panPin = 0; // Analog input for the joystick pan axis
int tiltPin = 1; // Analog input for the joystick tiltl axis
int zoomPin = 2; // Analog input for the zoom joystick axis 
int downPin = 3; // Analog input for the down axis

int tiltVal; // Value read from the vertical axis
int panVal; // Value read from the horizontal axis
int zoomVal; // Value read from the zoom axis
int downVal; // Value read from the down axis

void setup()
{
panServo.attach(9); // use pin 9 PWM output for pan servo
tiltServo.attach(10); // use pin 10 PWM output for tilt servo
zoomServo.attach(6); // use pin 6 PWM output for zoom servo
downServo.attach(5); // use pin 5 PWM output for down servo

}

void loop ()
{ 
panVal = analogRead(panPin); // read pan joystick position
panVal = map(panVal, 0, 1023, 0, 179); // scale reading to servo
panServo.write(panVal); //move servo to required position

tiltVal = analogRead(tiltPin); // read pan joystick position
tiltVal = map(tiltVal, 0, 1023, 0, 179); // scale reading to servo
tiltServo.write(tiltVal); //move servo to required postion

zoomVal = analogRead(zoomPin); // read zoom joystick position
zoomVal = map(zoomVal, 0, 1023, 0, 179); // scale reading to servo
zoomServo.write(zoomVal); //move servo to required position

downVal = analogRead(downPin); // read record joystick position
downVal = map(downVal, 0, 1023, 0, 179); // scale reading to servo
downServo.write(downVal); //move servo to required position
}

Sounds like a power supply problem. You need a separate power supply for the servos: 5-6 V at 3-4 amperes. A 4xAA battery pack is unlikely to work.

Be sure to connect the negative power supply lead to the Arduino ground.

Here are some threads discussing similar issues.

http://forum.arduino.cc/index.php?topic=366517.0

http://forum.arduino.cc/index.php?topic=370762.0

https://forum.arduino.cc/index.php?topic=368417.0

Thanks for the responses, but we arent sure how to separate the servos and give them a separate power supply since they are all connected to the arduino, which gets its power from the 9V outlet. And we still dont know what a joystick is, or how to hook it up with the arduino, or if we even need one to run a basic code. We also don't know anything about coding, so a simple code could help us alot. Thanks!

Attached is a pix of a servo external power setup. Note that breadboard connections are sometimes poor for motor setups.

servo power.jpg

Here's zoomkat's image.

servo power.jpg

The joysticks commonly used with an Arduino have two potentiometers (aka pots). Pots have three connections. One connection is set to 5V, on connection is set to ground. The middle connection known as the wiper connected to one of the Arduino's analog inputs.

Here are some joysticks gyrojeremy used in his robot arm (first link I gave earlier).

This joystick has three pots.

The third pot is in the knob.

It's also possible to use game controllers as inputs. Wii Nunchucks and PlayStation 2 game controllers are relatively easy to use with an Arduino.

And we still dont know what a joystick is, or how to hook it up with the arduino,

There is google and there is the forum search box in the upper right of this page. Basic research on your part is usually expected.