Adding a 'dead zone' to joystick controllers

Hi, In my code, there are 4 joysticks which can control 8 servos by sending data down a serial line to some other motor controllers I have. All I want to do is add a dead zone to the controllers, as they’re a bit crap, and are making the servos judder quite a lot.

I should say the sticks aren’t directly mapped to the servo positions, instead holding the stick up gradually increases the servo position.

const int module_id = 0; //Define this module as node 0. Due to 1 byte limit max number of modules is 225

int D = 5;  //Delay between sent messages

const byte JoystickCount = 4;
const byte AxisCount = JoystickCount * 2;

//                                     X1,  Y1,  X2,  Y2,  X3,  Y3,  X4,  Y4
float Positions[AxisCount] =         { 90,  90,  90,  90,  90,  90,  90,  90};
const int MinPositions[AxisCount] =  { 30,  30,  30,  30,  30,  30,  30,  30};
const int MaxPositions[AxisCount] =  {150, 150, 150, 150, 150, 150, 150, 150};

const byte AnalogPins[AxisCount] = {A0, A1, A2, A3, A4, A5, A6, A7};

void setup() {
  Serial.begin(38400); //Initialise Serial Comunications

void loop() {
  for (byte i = 0; i < AxisCount; i++)
    int analogInput = analogRead(AnalogPins[i]);
    float joystickOffset = (analogInput - 512) / 512.0;  // Reduce range to -1..+1
    Positions[i] += joystickOffset;
    if (Positions[i] > MaxPositions[i])
      Positions[i] = MaxPositions[i];
    if (Positions[i] < MinPositions[i])
      Positions[i] = MinPositions[i];

  send(1, 180 - Positions[1], Positions[0]);
  send(2, 180 - Positions[3], Positions[2]);
  send(3, 180 - Positions[5], Positions[4]);
  send(4, 180 - Positions[7], Positions[6]);

void send (int id, int Y, int X) {
  Serial.print(id); Serial.print(" ");
  Serial.print(Y); Serial.print(" ");
  Serial.print(X); Serial.print(" ");

All I want to do is add a dead zone to the controllers, as they're a bit crap, and are making the servos judder quite a lot.

I have no idea, in this context, what you mean by "dead zone". Are you expecting to have to push the joystick some distance before the servo starts to move?

Yeah exactly that. At the moment if the stick is not perfectly centred (which they never are because they’re cheap) then the positions of the servos will constantly increase.

So, before scaling to a float, check if the stick reading is within the dead zone range (what ever you want that to be). If so, set it to 512.

If it's outside the dead zone range, add/subtract half the dead zone width so that movement starts slowly as you just leave the dead zone.

    Positions[i] += joystickOffset;


    if (joystickOffset <-0.1 || joystickOffset > 0.1)
        Positions[i] += joystickOffset;

That would make the middle 20% of the range (10% either side of center) a dead zone.

Hello Arduino enthusiasts, i’m also have a question regarding joystick dead zones. I made a hydraulic handbrake, but i need some dead zones in the begging of reading input and in the end i need somehow cut the input because he read 100 and starts from 0. The data came from 1000 PSI Sensor.

Here is my short code:

#include <Joystick.h>

void setup()

{pinMode(A0, INPUT); 

const int pinToButtonMap = A0;

void loop(){
int pot = (analogRead(A0));
int mapped = map(pot,100,700,0,255);

IMG_1 When handbrake is no used, he still showing about 1-2%, if i increase a value 100 in map(pot,100,700,0,255); it come to 0 value but it start being very accurate, and move to different side to 100%.

IMG _2 When handbrake is fully pulled it showing about 85%, but at this zone it must be about 99-100%.