Controlling Servo Angle using Joystick in Arduino IDE

Controlling Servo Motor
About This Tutorial
In this tutorial we will control the position of a RC (hobby) servo motor with a Joystick.
Tutorial Info


In this tutorial we will control the position of a RC (hobby) servo motor with a Joystick.

A servo motor is a rotary actuator that allows for precise control of angular position.  It consists of a suitable motor coupled to a sensor for position feedback.

Metal Servo motor

Control using evive and Arduino IDE

evive has two dedicated servo motor outputs pins.

Signal pin of servo 1 is connected to digital pin 44 and servo 2 is connected to digital pin 45.

evive servo output channel

Circuit Diagram

In the following example, I will be showing you how to control servo through channel 1. Given below is the circuit diagram:

evive Servo Joystick

A Servo pin has three wires (Order to be connected in evive, left to right)

  • Brown wire: GND
  • Red wire: VCC
  • Orange wire: Signal
Caution: Power evive using a 12V 2A power adapter for smooth functioning of servo motor. The VVR (Variable voltage) should be close to 6V.

A Joystick have 5 pins:

  • Ground
  • 5V
  • VRx: X position connects to Analog pin 0
  • VRy: Y position
  • SW: Z press

How Joystick works?

Joystick has 2 potentiometers and a switch.
A potentiometer has a wiper sliding on a resistive strip. If the wiper is close to GND, it outputs 0V, and if it is close to VCC or 5V, it outputs 5V.
In Arduino IDE,  if the wiper is close to GND you get 0 value and if it close to VCC, you get 1023. Hence you get approx. 512 when joystick is at default position.


[pastacode lang=”c” manual=”%23include%20%3Cservo.h%3E%0A%0Adouble%20Angle%3B%0Adouble%20Potentiometer%3B%0AServo%20servo_3%3B%0A%0Avoid%20setup()%7B%0A%20Angle%20%3D%200%3B%0A%20pinMode(A0%2CINPUT)%3B%0A%20servo_44.attach%7B44)%3B%20%2F%2F%20init%20pin%0A%7D%0A%0Avoid%20loop()%7B%0A%20Potentiometer%20%3D%20analogRead(A0)%3B%0A%20Angle%20%3D%20((Potentiometer)%20*%20(180))%20%2F%20(1023)%3B%0A%20servo_44.write(Angle)%3B%20%2F%2F%20write%20to%20servo%0A%20delay(50)%3B%0A%7D” message=”” highlight=”” provider=”manual”/]

Control using Arduino Uno

Arduino uno has 6 PWM pins: 3, 5, 6, 9, 10, and 11 which provide 8-bit PWM output with the analogWrite() function.

We will controlling servo using Pin 3.

Circuit Diagram

Caution: Power servos using a 6V 2A power adapter for smooth functioning of servo motor.


[pastacode lang=”c” manual=”%23include%20%3Cservo.h%3E%0A%0Adouble%20Angle%3B%0Adouble%20Potentiometer%3B%0AServo%20servo_3%3B%0A%0Avoid%20setup()%7B%0A%20Angle%20%3D%200%3B%0A%20pinMode(A0%2CINPUT)%3B%0A%20servo_3.attach(3)%3B%20%2F%2F%20init%20pin%0A%7D%0A%0Avoid%20loop()%7B%0A%20Potentiometer%20%3D%20analogRead(A0)%3B%0A%20Angle%20%3D%20((Potentiometer)%20*%20(180))%20%2F%20(1023)%3B%0A%20servo_3.write(Angle)%3B%20%2F%2F%20write%20to%20servo%0A%20delay(50)%3B%0A%7D” message=”” highlight=”” provider=”manual”/]

This helped
This didn't help
Share this Tutorial
Share on facebook
Share on twitter
Share on google
Share on pinterest
Share on reddit
Share on print
Related Projects & Tutorials
Interfacing Relay with evive
This tutorial explains interfacing of a relay module with evive for controlling high power circuits like AC bulb with help of evive.
evive arduino variables
Arduino IDE: Variables
A variable is used in programming to store a value (integer, float, character or string) that may change during the life of the Arduino sketch.
All articles loaded
No more articles to load
Featured Projects
DIY Robotic Arm Bartender

This project will show you how to make your own robotic arm bartender that will make you a star host!

All articles loaded
No more articles to load
Close Menu