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
3 x Custom 3D-printed caps (paddle, cup/trigger, and thumbstick styles)
12 x M3 nuts
1 x Soldering iron
1 x Solder spool
1 x Wire snips
1 x Wire stripper
1 x USB-C cable
Voxelab Aries FDM 3D printer (or equivalent FDM 3D printer)
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.
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
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:
Single_Axis_Joystick_Demo_Box.ino
Simple demo code for demonstrating use of single-axis joysticks with:
An RGB LED
A hobbyist servo motor (SG90)
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:
Initial readings are taken for the 3 x joysticks.
The joystick readings are continuously read in the loop() function, and rolling averages are taken to smooth them out to reduce jitter/signal noise.
The Arduino map() function is used to convert the joystick readings into values that are then used for:
LED brightness and color (red when the joystick is pushed forward, and green when it is pulled back
Servo angular position
Stepper motor jog speed and direction
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.
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 :
Taking analog readings from 3 x single-axis joystick modules.
Controlling the color and brightness of an RGB LED using the SoftPWM library.
Controlling the position of a hobbyist servo motor (SG90).
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
Comments