I would like to make an RC controller with NRF24L01 and two dx6i clone joysticks.

Problem Joystick potentiometer return shitty value. When I move it, the "middle point value change" as well "extremity point".

Value of potentiometer at middle point Value of potentiometer at middle point

I use a function for smooth data but sometime "middle point" is 982, 983 or 979.

What can I do to get goods values? Potentiometer is directly connected to the Arduino.

My code

int cardan1X = A0;
bool sens; //sens = 1 -> forward; sens = 0 -> backward; 
int cardan1XVal;            //not smoothed value
int cardan1XValSmooth = 0;  //smoothed value
float smoothStrength = 5;   //Strength of smooth

void setup() {
  pinMode(cardan1X, INPUT);

void loop() {

  cardan1XVal = analogRead(cardan1X);
  cardan1XValSmooth = smooth(cardan1XVal, cardan1XValSmooth);
  Serial.println(String(cardan1XVal) + " ---> " + String(cardan1XValSmooth));

float smooth(int t_rawVal, float t_smoothedVal) {
    return  t_smoothedVal + ((t_rawVal - t_smoothedVal) + 0.5) / smoothStrength;  // +0.5 for rounding
  • 2
    It is traditional with joysticks to program in a "dead zone" in the middle. You have to move it above a certain amount for it to then register as being moved. – Majenko Dec 24 '18 at 12:27

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.