ESP8266 - Joystick - Servo Motor
A joystick is equipped with two potentiometers that are perpendicular to each other (known as the X-axis and Y-axis). These potentiometers output analog values (X-value and Y-value) on VRX and VRY pins. We will use these analog values to independently control two servo motors: X-value controls servo #1 and Y-value controls servo #2. When using a pan-tilt kit, the combination of the two servo motors creates three-dimensional movement.
There are two use cases:
- Use case 1: The servo motors rotate according to the movement of the joystick's thump:
- The angles of servo motors are in proportion to the values of the joystick's X-value and Y-value.
- When the joystick's thump is released, all values return back to the center values and the servo motors automatically go back to the center position.
- Use case 2: Use the joystick to command servo motors (up/down/left/right commands)
- When the joystick's thump is pushed to the left, move the servo motor #1 in a clockwise direction.
- When the joystick's thump is pushed to the right, move the servo motor #1 in an anti-clockwise direction.
- When the joystick's thump is pushed up, move the servo motor #2 in clockwise direction.
- When the joystick's thump is pushed down, move the servo motor #2 in an anti-clockwise direction.
- When the joystick's thump is released, the servo motors will not return to the center position.
- If the joystick is pressed (push button), the servo motors will return to the center position.
- Analog to Digital Module:
- You can use an external Analog to Digital Converter (ADC) module like the popular ADS1115 ADC Module.
- This module lets you connect multiple analog devices, expanding the available analog input pins.
- Multiplexing Solution:
- Another option is to implement a multiplexing solution. This involves switching between reading the X and Y axes of the joystick using the single available analog input pin.
- Essentially, you switch back and forth between X and Y readings, achieving the desired functionality through time-division multiplexing.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of Joystick and Servo Motor
If you are unfamiliar with joystick and servo motor (including pinout, functionality, programming, etc.), the following tutorials can help:
Since the ESP8266 has only one analog input pin, and the joystick needs two, there are two ways to solve this:
However, both these solutions can be a bit costly and complicated. For a simpler approach, we highly recommend using the ESP32 instead of the ESP8266. Check out the ESP8266 - Joystick tutorial for a more user-friendly implementation.