SERVO+ARDUINO HELP

I don’t understand why my robotic arm is not working. If anyone can tell me why, based on the description below, before three o’clock pm, I would appreciate it.

I have:

-four servos (3 are HS422s, one is the “medium servo” from Sparkfun) connected to an Arduino; one with signal to pin 6, one to pin 9, one to pin 10, and one to 11

-each of the servo’s are in parallel to the power source (which is the 5 volt breadboard power supply from Sparkfun)

-four 10K pots (2 are in a joystick config, however) connected to Arduino; one on analog pin 0, one on 1, one on 2 and one on 3

-the grounds are connected

-the Arduino is powered via USB, the rest via the power supply

Arduino is running this code:

#include <Servo.h> 
 
Servo sm1;  
Servo sm2;  
Servo sm3;  
Servo sm4;  
 
int pot1 = 0;  
int pot2 = 1;
int pot3 = 2;
int pot4 = 3;

int val1;
int val2;
int val3;
int val4;
 
void setup() { 
  sm1.attach(6);  
  sm2.attach(9);
  sm3.attach(10);
  sm4.attach(11);
  
} 
 
void loop() { 
  val1 = analogRead(pot1); 
  val2 = analogRead(pot2);
  val3 = analogRead(pot3);
  val4 = analogRead(pot4);
  
  val1 = map(val1, 0, 1023, 0, 179);    
  val2 = map(val2, 0, 1023, 0, 179);
  val3 = map(val3, 0, 1023, 0, 179);
  val4 = map(val4, 0, 1023, 0, 179);
  sm1.write(val1);   
  sm2.write(val2);
  sm3.write(val3);
  sm4.write(val4);
  delay(15);                           
}

The motors dont respond at all until I unplug one or two, and then they jerk around and go crazy. Please help me!

The code looks all right. My guess is there is some feedback and power issues. The surge of current required to drive the servo is feeding into the ground plane or causing a V droop. Try adding another bread board power supply in parallel to give the system a bit more power stability. Try to keep the grounds of the motor separate from the ground for the arduino untill it gets back to the supply. This will prevent current from raiseing the voltage of ‘ground’ and potentially causeing the arduino to reset. Try using just one servo, get that one sorted then add a second servo and get things working again. repeat until all 4 are attached. By then you should have a good idea what’s going on in the system. Be sure to monitor your power supply voltage and current, not only at the supply but at the source for the servos.

standard pwm wont work. use the servo library

http://www.arduino.cc/playground/ComponentLib/Servo