top of page
Writer's pictureEST - Austin

Single Axis Joystick Controller with Arduino

Introduction

In this project, I demonstrate three different use cases for single-axis joysticks with an Arduino Nano microcontroller. The joysticks used in this project can be found here!

Single-axis joysticks have historically been out of reach for hobbyists due to their large size and high cost, and while dual-axis joysticks are ubiquitous and commonly available, sometimes a user just wants to control a single axis.


For example:

  • Controlling the light output level from an LED

  • Setting the angle of a rudder, airfoil, or RC car's steering angle for hobbyist projects using a low-cost SG90 servo motor

  • Jogging the position of a stepper motor on a DIY CNC machine


In this article, I share a demo unit that utilizes 3 x single-axis joystick module breakout boards to demonstrate these three applications!



Disclosure: Some of the links in this article are affiliate links. This means that, at zero cost to you, I will earn an affiliate commission if you click through the link and finalize a purchase.


Supplies

  1. 3 x Single-axis joystick modules

  2. 3 x Custom 3D-printed caps (paddle, cup/trigger, and thumbstick styles)

  3. 3mm thick black acrylic sheet

  4. 6 x M3 x 12mm black oxide screws

  5. 6 x M3 x 6mm black oxide screws

  6. 12 x M3 nuts

  7. 12 x M3 x 11mm length male-female hex standoffs

  8. 12 x M2 x 4mm black oxide screws

  9. 6 x 3D-printed foot caps

  10. 1 x 3D-printed enclosure wall

  11. 1 x 5-pin aviation connector

  12. Assorted 22 AWG solid-core hookup wire

  13. 1 x Soldering iron

  14. 1 x Solder spool

  15. 1 x Wire snips

  16. 1 x Wire stripper

  17. 1 x Half-size breadboard

  18. 1 x Arduino Nano clone board

  19. 1 x USB-C cable

  20. 1 x Common-anode diffused surface THT RGB LED

  21. 1 x NEMA17 stepper motor

  22. 1 x TMC2208 stepper motor driver breakout board

  23. 1 x 12VDC power supply (wall wart) for the stepper motor

  24. 1 x SG90 hobby servo motor

  25. 1 x Spool of 1.75mm black PLA filament

  26. Voxelab Aries FDM 3D printer (or equivalent FDM 3D printer)

  27. Laptop or PC to program the Arduino unit



Mechanical Hardware

The demo unit was created by laser-cutting sheets of 1/8" thick black acrylic. The DXF file used to create the laser cutting files was made using Autodesk Fusion 360. The side wall of the demo enclosure was 3D printed using black PLA filament, and then M3 threaded inserted were installed around the top and bottom rims using a standard soldering iron. Some screw caps were also printed using black PLA filament for the demo unit to rest on. The top 3 x joystick caps were designed in Autodesk Fusion 360 and printed using the same PLA filament, and they were designed to be press-fit onto the joystick handles.




The three styles of joystick I demonstrate here are:

  • Paddle type, for controlling the color and brightness of the RGB LED

  • Cup/trigger type, for controlling the position of the servo motor, e.g. for hobbyist RC boats, planes, and vehicles

  • Thumbstick type, used for jogging the position of a stepper, brushed DC, or BLDC motor


The top and bottom laser-cut acrylic sheets are fastened to the 3D-printed enclosure wall using M3 screws, and M2 standoffs + screws and nuts secure the 3 x joysticks to the underside of the top face of the demo unit. A 5-pin aviation connector is mounted to the side of the demo's printed enclosure wall.





Electrical Hardware

Solder the 22 AWG hookup wire to provide power (VCC, 5V) and GND to each of the three single-axis joysticks in parallel. Run one wire to each of the signal pads on each single-axis joystick board, and solder all 5 x wires to the aviation connector mounted on the side wall of the demo enclosure.


Single-Axis Joystick Control Demo with Arduino
Single-Axis Joystick Control Demo with Arduino


Build the breadboard circuit for the Arduino Nano clone board as shown in the image below. The pin connections leading to the Arduino are as follows:

  • D2: LED Red

  • D3: LED Green

  • D4: LED Blue

  • D5: Servo PWM Signal

  • D7: TMC2208 STEP

  • D8: TMC2208 DIR

  • A0: Joystick 1 Signal

  • A1: Joystick 2 Signal

  • A2: Joystick 3 Signal



Single-Axis Joystick Control Arduino Wiring Diagram/Schematic
Single-Axis Joystick Control Arduino Wiring Diagram/Schematic


The Arduino Nano receives its 5V power from its USB port, which you can connect to a 5VDC external power supply, or to a typical PC/laptop USB port. The stepper motor is run off an external 12VDC power supply, and controlled using the TMC2208 stepper motor driver. Take care not to connect 12V positive power to any of the Arduino pins, or you risk damaging the Arduino!


Programming

The code used to create this project can be found on my Github page:

  1. Single_Axis_Joystick_Demo_Box.ino

    1. Simple demo code for demonstrating use of single-axis joysticks with:

      1. An RGB LED

      2. A hobbyist servo motor (SG90)

      3. A NEMA17 stepper motor


The code is loaded onto the Arduino Nano using the Arduino IDE, which is free software often used for hobbyist projects!


The general working principle of the code is as follows:

  1. Initial readings are taken for the 3 x joysticks.

  2. The joystick readings are continuously read in the loop() function, and rolling averages are taken to smooth them out to reduce jitter/signal noise.

  3. The Arduino map() function is used to convert the joystick readings into values that are then used for:

    1. LED brightness and color (red when the joystick is pushed forward, and green when it is pulled back

    2. Servo angular position

    3. Stepper motor jog speed and direction

  4. The LED brightness is set using the SoftPWM library. PWM stands for pulse-width modulated, which is useful for setting the effective brightness of an LED. By pulsing it for more On time than Off time, the LED will appear brighter, and this is how it appears to the eye when it is powered on and off quickly.

  5. The servo position is controlled using an Arduino Servo object definition which, similar to SoftPWM, sends a PWM signal to the servo motor, whose on-board circuitry controls its position.

  6. The stepper motor jogging speed and direction is set using the AccelStepper library, which is useful for defining accelerations and velocities for controlling stepper motors.



Demonstration

The linked video below introduces the single-axis joystick breakout modules, and shares the demo unit showcasing their versatility in the following three uses cases!

  • Controlling the light output level from an LED

  • Setting the angle of a rudder, airfoil, or RC car's steering angle for hobbyist projects using a low-cost SG90 servo motor

  • Jogging the position of a stepper motor on a DIY CNC machine





Conclusion

In this article, I introduced a single-axis joystick breakout module which is perfect for hobbyists looking for a lost-cost, small form factor joystick for user input along a single axis! The demo unit above demonstrates the versatility of these single-axis joystick modules for many different types of projects. The modules can be purchased from Elation Sports Technologies here:


In the demo unit, multiple concepts were covered, utilizing an Arduino Nano development board :

  1. Taking analog readings from 3 x single-axis joystick modules.

  2. Controlling the color and brightness of an RGB LED using the SoftPWM library.

  3. Controlling the position of a hobbyist servo motor (SG90).

  4. Setting the jog speed/velocity of a NEMA17 stepper motor using the AccelStepper library.


Check out our other blog posts! To subscribe to our free newsletter, click the Log In button in the top right corner of this page so you never miss a post:


My business offers mechanical and electrical engineering design consulting. I'd be happy to discuss your project's needs to see how we may assist you - simply reach out to schedule a chat.


Thanks for reading!


Austin Allen

Founder and Owner

Elation Sports Technologies LLC


18 views0 comments

Comments


bottom of page