I will show you the control of two servo motors with a joystick.
Actually this is a simple project, but many followers wanted me to share this project.
So how does it work?
When the joystick module moves horizontally or vertically, it gives values from 0 to 1023.
We will scale the servo motor positions to the joystick values using the map function.
Thus, the servo motors will move according to the scaled value.
The connection part of this project is very easy to make.
First, use a mini breadboard to separate 5 volts from the Arduino.
Connect the VCC inputs of the servo motors and the joystick module to the 5 volts on the breadboard.
Do not forget! Use an external power supply if the servo motors requires high power and current.
Connect the GND (ground) inputs of all components to the GND inputs on the Arduino.
Connect one of the signal inputs of the servo motors to digital input PWM 3, and the other to digital input PWM 5 of the Arduino.
Connect the X signal input of the joystick to the Analog 0 input of the Arduino.
Then connect the Joystick Y signal input to the Arduino's Analog 1 input.
All connections should look like the circuit diagram shown.
To explain the source code briefly:
I included the library for the servo motor which will help us with making the code easier.
Then, I initialized two variables, one for each of the two servo motors which will help us in using the library functions.
I initialized the pins where I have connected the vertical and horizontal pins on the joystick module and also the signal pins on the servos.
In the "Void setup" section I have defined the pins where the servo motors are attached.
I have added all explanations in the code. You can find the source code link in the video description.
