Servo and Joystick

Do need some help please
Having trouble with my servos and joystick
Have two joysticks connected to four servos
Problem when moving one joystick three of the servos move
Have them connected through Sensor shield with external power supply 5V

#include <meArm.h>

#include <Wire.h>

/* meArm IK joysticks - York Hackspace May 2014
 * Using inverse kinematics with joysticks
 * Uses two analogue joystcks (two pots each)
 * First stick moves gripper forwards, backwards, left and right
 * Second stick moves gripper up, down, and closes and opens.
 * I used Sparkfun thumbstick breakout boards, oriented 'upside down'.
 * Pins:
 * Arduino    Stick1    Stick2    Base   Shoulder  Elbow    Gripper
 *    GND       GND       GND    Brown     Brown   Brown     Brown
 *     5V       VCC       VCC      Red       Red     Red       Red
 *     A0       HOR
 *     A1       VER
 *     A2                 HOR
 *     A3                 VER
 *     11                       Yellow
 *     10                                 Yellow
 *      9                                         Yellow
 *      6                                                   Yellow
//#include "meArm.h"
#include <Servo.h>

int basePin = 12;
int shoulderPin = 9;
int elbowPin = 6;
int gripperPin = 3;

int xdirPin = 0;
int ydirPin = 1;
int zdirPin = 4;
int gdirPin = 3;

meArm arm;

void setup() {
  arm.begin(basePin, shoulderPin, elbowPin, gripperPin);

void loop() {
  float dx = map(analogRead(xdirPin), 0, 1023, -5.0, 5.0);
  float dy = map(analogRead(ydirPin), 0, 1023, 5.0, -5.0);
  float dz = map(analogRead(zdirPin), 0, 1023, 5.0, -5.0);
  float dg = map(analogRead(gdirPin), 0, 1023, 5.0, -5.0);
  if (abs(dx) < 1.5) dx = 0;
  if (abs(dy) < 1.5) dy = 0;
  if (abs(dz) < 1.5) dz = 0;
  if (!(dx == 0 && dy == 0 && dz == 0))
    arm.goDirectlyTo(arm.getX() + dx, arm.getY() + dy, arm.getZ() + dz);
  if (dg < -3.0)
  else if (dg > 3.0)

It looks to me like you are using a library intended to control a robotic arm.
Moving one joystick in such a system will cause the library to compute new positions for all 3 position servos.
The 4th servo I expect only to move when the joystick for the gripper is moved.

edit: I should ask - are you trying to control a 4 servo arm designed like the Phenoptix meArm? That is where I found a library with the same name as the one you are using. If you are just trying to drive 4 servos independently, one servo to a joystick axis, then that library might not be the best fit.

Yes that is what I,m trying to do.
Can you suggest what library and code
I could use please

I am not sure which question you are answering.
Are you trying to drive 4 servos independently, one servo to a joystick axis?

edit: if so, I think you can get away with standard servo.h references to your servos. I am not an expert at interpreting code in libraries, but I did look, and it appears that the meArm library talks to the servos using servo.h
So you should be able to do so also.

You can confirm this by running the servo sweep tutorial. Use pin numbers from your existing sketch.
12, 9, 6 or 3. That will tell us if you can talk to the servos. Then you can read your joysticks and use the results to drive the servos as is done in the servo knob example

Thanks vinceherman
Did use the joystick knob sketch and added two more servos and another joystick
that worked out fine