Dual Axis XY Joystick Module
$31.5
$58.59
Smooth gradation of values – see code… I’m not sure why some folks are having issues getting a smooth sample of values across the stroke of the joystick’s axis. It is important to note these are not intended to be maxed out to an extent position anyway. You can only move about half way or a little more to the edge before it is overwhelmed. So perhaps people are just not moving slowly. Got me. But here is some code I used to test mine with. No issues. I hope this helps someone…/* micro joystick test sketch / atomkey 2019 doesn’t test for the push button feature – that’s simple ~does test for the analog read on the x and y axis I coded this for folks that have said there are only three gradations of measure they can get. This runs fine on my Arduino and generates a smooth gradation from 1024 max to 512 center and then to 0 minimum. Keep in mind the joystick isn’t intended to be moved to its extreme extents. The boundry is not at the outer edge. 4 wires from the joystick to the arduino 2 for the axis 1 for the ground and 1 for the 5v */int sensorPinX = A0; // input pin joystick x axisint sensorPinY = A1; // input pin joystick y axisint sensorValueX = 0; // variable x axisint sensorValueY = 0; // variable y axisvoid setup() { Serial.begin(9600);}void loop() { // read the x,y values from the sensor: sensorValueX = analogRead(sensorPinX); sensorValueY = analogRead(sensorPinY); Serial.print(sensorValueX); // show results Serial.print(” “); // on serial monitor as Serial.println(sensorValueY); // two columns of data delay(150); // for even smoother (stable) results you can perform a // mean sample run. That’s where you sample the signal // n times over t seconds and take the average of the reads.}
Sensors & Modules