ESP8266 - Joystick

Hardware Preparation

1×ESP8266 NodeMCU
1×Micro USB Cable
1×Joystick
1×Jumper Wires
1×(Optional) 5V Power Adapter for ESP8266
1×(Optional) ESP8266 Screw Terminal Adapter

Or you can buy the following sensor kit:

1×DIYables Sensor Kit 30 types, 69 units
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you. We appreciate your support.

Overview of 2-axis Joystick

You may have encountered a Joystick in various places, like a game controller, a toy controller, or even a large machine like an excavator controller.

The joystick is made up of two potentiometers arranged perpendicular to one another and a push button. Thus, it produces the following outputs:

  • An analog value ranging from 0 to 1023 that corresponds to the horizontal position (known as the X-coordinate)
  • An analog value ranging from 0 to 1023 that corresponds to the vertical position (known as the Y-coordinate)
  • A digital value of the push button (either HIGH or LOW)

Therefore:

  • Two analog values can be merged to form 2-D coordinates
  • Center of the coordinates is the resting position of the joystick
  • A test code (presented in the next section) can determine the actual direction of the coordinates

Some applications may use all three outputs, while others may only use a subset of them.

ESP8266 and Joystick

Because the ESP8266 only has one analog input pin, and the joystick needs two, there are two ways to tackle this:

  • Analog to Digital Module:
    • You can add an external gadget called an Analog to Digital Converter (ADC) module, like the ADS1115 ADC Module.
    • This nifty device gives you more analog input pins, letting you connect multiple analog devices, including the joystick.
  • Multiplexing Solution:
    • Another option is to use a multiplexing solution, where you take turns reading the X and Y axes of the joystick using that single analog input pin.
    • This involves switching between the X and Y axes at different times, using a technique called time-division multiplexing.

    However, both of these options can be a bit pricey and a tad complicated. Instead, we recommend going for the ESP32 instead of the ESP8266. Check out the ESP8266 - Joystick tutorial for a simpler and more effective way to go about it.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!