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
}