Till now we have discussed various Arduino boards and the construction of different projects using them. In today’s article, we will be going to discuss one of the most searched Arduino projects which is a joystick servo controller with Joystick Arduino & Pan-Tilt Mechanism.
The servo motor with a pan tilt mechanism has been in use for a long period. whether it is for a pan tilt zoom camera or any other applications which require 180 or 360 degrees of movement. With time new discoveries have been made in this field which enhanced its capabilities. Today we will be discussing controlling a servo motor with a pan-tilt mechanism with the help of a joystick and Arduino but, before moving further if have not checked out the joystick mechanism and Arduino UNO Rev 3, we recommend you check it out first.
What Is a Joystick Servo Controller?
The Joystick controller is typically a thumbstick that is used to control the motion or movement of any object. The Joystick Controller is especially used in robotics. The user pushes the thumb stick in different directions to control the movements of the object.
The Joystick Servo Controller is an analog joystick that is more sensitive and more precise than any ordinary directional joysticks available in the market. These Joystick Servo Controllers have a lever that is used to control the movement. The lever of the joystick can be moved in different directions on the x-axis and y-axis.
The Arduino Joystick Servo Controller can be made up of different Arduino boards(i,e Atmega, etc) but in this tutorial, we will be going to use Arduino UNO.
In today’s tutorial we will be going to discuss how to make a joystick controller using Arduino UNO and how it works but before moving further if you don’t know what is Arduino UNO and how it works then we will recommend you check out it before moving further in this tutorial.
What Is Pan Tilt Mechanism?
Pan Tilt mechanisms are used where the preciseness of the location is an utmost priority. It basically has two motors that follow motion-on-motion design principles. In the pan-tilt mechanism, one motor controls the axis of the motion meanwhile the second motor which is larger in size than the first motor moves the first motor along with the load it is carrying to the other axis.
In this way, we can move the load around the axis covering a wide range of angles which is required.
Requirements For Making Joystick Servo Controller
The requirements for making a servo controller with a joystick and Arduino are as follows:-
S.No | Item | Quantity |
1 | Arduino UNO Rev3 | 1 pc |
2 | Breadboard | 1 pc |
3 | Joystick Module | 1 pc |
4 | Servo Motors | 2 pc |
5 | Male to Female jumper wires | 4 pc |
6 | Male to Male jumper wires | 8 pc |
7 | Pan Tilt Mechanism | 1 pc |
That is all in the requirements for making a servo controller with a joystick and Arduino. Now, let us discuss the connection of the circuit.
What are Servo Motors?
A Servo motor is basically a motor or actuator which is used for a precise linear position as well as angular position and velocity etc. Servo motors are closed-loop servomechanism and that is why it uses position feedback to control the position and motion. Servo motors can rotate up to 180 degrees making the movement more precise.
Servo motors are widely used in robotics, DVDs and remote control toy cars, and many more electrical components. There are a total of 3 wires present in the servo motors which are needed to be connected for proper functioning.
The pin configuration of the servo motor is as follows:-
Wires of the servo motor | Color of the wires |
Vcc Pin | Red |
GND or Ground Pin | Brown |
Pulse Width Modulation Pin | Yellow or Orange |
What is Joystick Mechanism?
The Joystick module is an input device that has a lever. This lever can be moved in different directions in the x-axis and y-axis. As stated earlier it is an analog input mechanism hence we need two analog reading pins which are built into the microcontroller we are using.
These analog pins are used to determine the values of the X-axis and Y-axis. The values of the X-axis and Y-axis are used to interpret the position of the lever. The values of the X-axis and Y-axis range from 0 to 1023. As we already know that the Arduino UNO Rev 3 has an in-built ADC (Analog To Digital) converter.
These analogs To Digital converters are used to convert the value of the voltage from 0 volts – 5 volts to 0 to 1023 values. The joystick module has two variable resistance or potentiometers and a push button also. These potentiometers are 10k each for the x-axis and y-axis respectively.
For more check How 2-Axis Joystick Works & Interface with Arduino.
The Joystick mechanism has 5 wires which are:-
- Vcc
- Xout or VRX
- Yout or VRY
- GND
- Sel or SW
Circuit Connection
- Connection OF Servo And Arduino UNO Rev 3
Step 1 – Connect the Vcc or +5v of both of the servo motors to the Vcc or +5v of the Arduino UNO Rev 3.
Step 2 – Connect the GND pin of both of the servo motors to the GND pin of the Arduino UNO Rev 3.
Step 3 – Connect the Yellow/Orange signal pins of both servos to pin number 10 and pin number 11 of the Arduino UNO Rev 3 respectively. Pins 3,4,5 are PWM-enabled pins.
- Connection OF Joystick Module With Arduino UNO Rev 3
Step 1 – Connect the GND pin of the joystick module to the GND pin of the Arduino UNO Rev 3.
Step 2 – Connect the 5v or Vcc pin of the joystick module to the 5v or Vcc pin of the Arduino UNO Rev 3.
Step 3 – Connect the VRx or X-out pin of the joystick module to the analog pin 3 of the Arduino UNO Rev 3.
Step 4 – Connect the VRy or Y-out pin of the joystick module to the analog pin 4 of the Arduino UNO Rev 3.
Step 5 – Connect the SW or Sel pin of the joystick module to the digital pin D2 of the Arduino UNO Rev 3.
That is all in the circuit configuration of the joystick servo controller.
Arduino Code Required For The Project
The coding required for the completion of the project is as follows:-
#include <Servo.h>
const int servo1 = 11; // first servo
const int servo2 = 10; // second servo
const int joyH = 3; // L/R Parallax Thumbstick
const int joyV = 4; // U/D Parallax Thumbstick
int servoVal; // variable to read the value from the analog pin
Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
void setup() {
// Servo
myservo1.attach(servo1); // attaches the servo
myservo2.attach(servo2); // attaches the servo
// Inizialize Serial
Serial.begin(9600);
}
void loop(){
// Display Joystick values using the serial monitor
outputJoystick();
// Read the horizontal joystick value (value between 0 and 1023)
servoVal = analogRead(joyH);
servoVal = map(servoVal, 0, 1023, 0, 180); // scale it to use it with the servo (result between 0 and 180)
myservo2.write(servoVal); // sets the servo position according to the scaled value
// Read the horizontal joystick value (value between 0 and 1023)
servoVal = analogRead(joyV);
servoVal = map(servoVal, 0, 1023, 70, 180); // scale it to use it with the servo (result between 70 and 180)
myservo1.write(servoVal); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
/**
* Display joystick values
*/
void outputJoystick(){
Serial.print(analogRead(joyH));
Serial.print ("---");
Serial.print(analogRead(joyV));
Serial.println ("----------------");
}
Frequently Asked Questions
Q1 – Can servo motors rotate 360?
Ans – No, the servo motor can only rotate up to 180 degrees however if you need 360-degree rotation then you can use continuous’ servos that can rotate through the full 360 degrees.
Q2 – Are servo motors ac or dc?
Ans – Servo motors are both AC and DC as there are two types of servo motors available which depend on AC supply like electric outlet and DC supply like batteries.
Q3 – Are servo motors brushless?
Ans – Yes, servo motors are brushless.
Q4 – Do servo motors have Encoders, Drivers, and Brakes?
Ans – Yes, servo motors have encoders, drivers, and brakes.
1 thought on “How To make a joystick servo controller with Joystick, Arduino & 1 Pan-Tilt Mechanism. ”