Good afternoon,
i've got a problem using an RC joystick with arduino.
My plan is to create a rc controller, so i bought some 2 axis joystick from aliexpress (joysticks look professional) from this link here:
The problem is that when i use analogRead Function the results are really unstable and they are not going from 0 to 1023, but into a very strict interval with variable range.
I tryed to figure out what's wrong, here down i let you my code:
//Inputs outputs
int throttle_in = A0;
int yaw_in = A1;
int pitch_in = A2;
int roll_in = A3;
int throttle_to_send;
int yaw_to_send;
int pitch_to_send;
int roll_to_send;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
}
void loop() {
delay(1000);
// put your main code here, to run repeatedly:
throttle_to_send = analogRead(throttle_in);
yaw_to_send = analogRead(yaw_in);
pitch_to_send = analogRead(pitch_in);
roll_to_send = analogRead(roll_in);
Serial.print("\n\nREADING...\n");
Serial.print("\nThrottle: ");
Serial.print(throttle_to_send);
Serial.print("\nYaw: ");
Serial.print(yaw_to_send);
Serial.print("\nPitch: ");
Serial.print(pitch_to_send);
Serial.print("\nRoll: ");
Serial.print(roll_to_send);
}
I used an Arduino NANO R3, for the schematic i used four potentiometer instead of two joystick, but i think it's the same (Joystick's resistors are 5Kohm).
All the ground wires are connected to arduino so i'm exluding this issue, but i don't really know how to solve this problem.
I wired up 2 joysticks to my Uno to test your code. I get stable values from near 0 to near 1023 all 4 axes. I suspect a wiring mistake or bad parts. Do you have a DMM to measure your pots pinouts?
I suspect a bad connection or some wires going to the wrong place.
Do you have a multimeter to check the joystick pots? The two outside connectors should measure a constant resistance that should be the same for all of the pots (that is where +5 and Ground connect). The center connection should show a variable resistance to both ends as you move the joystick. That's the connection that goes to the analog input.
I will test with a multimeter, but now i'm not able to mesure because i don't have one...
It could be maybe the input voltage of the joystick potentiometer? (Now it's running at 5V)
Or maybe a not usual type of potentiometer?
It is difficult to follow the wiring in the photo.
Here is how I think that the potentiometers in the joysticks are wired. Red to Vcc, White to ground and black to analog input. This is based on an educated guess with 50 years of experience behind it and it agrees with the description by @ johnwasser.
It looks like the WHITE wires are being connected to the analog inputs. That would be a mistake. The ORANGE wires go to +5V, the WHITE wires go to Ground and the middle BLACK wires go to the analog inputs.