Darwin Dela Cruz
Published © LGPL

How to Control Single Servo Motor by Joystick

Mabuhay! Darwin here. In this project, I will teach you how to control a servo motor using a joystick module.

EasyShowcase (no instructions)1 hour10,143
How to  Control Single Servo Motor by Joystick

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
Servos (Tower Pro MG996R)
Jumper wires (generic)
Jumper wires (generic)

Software apps and online services

Arduino IDE
Arduino IDE


Read more



Aa lqb2f2ad3r


Untitled file

#include <Servo.h>
#define SERVO_PIN 9
#define GROUND_JOY_PIN A3            //joystick ground pin will connect to Arduino analog pin A3
#define VOUT_JOY_PIN A2              //joystick +5 V pin will connect to Arduino analog pin A2
#define XJOY_PIN A1                  //X axis reading from joystick will go into analog pin A1
Servo myservo ;
void setup()
 pinMode(VOUT_JOY_PIN, OUTPUT) ;    //pin A3 shall be used as output
 pinMode(GROUND_JOY_PIN, OUTPUT) ;  //pin A2 shall be used as output
 digitalWrite(VOUT_JOY_PIN, HIGH) ; //set pin A3 to high (+5V)
 digitalWrite(GROUND_JOY_PIN,LOW) ; //set pin A3 to low (ground)
void loop()
 int joystickXVal = analogRead(XJOY_PIN) ;  //read joystick input on pin A1
 Serial.print(joystickXVal);                //print the value from A1
 Serial.println(" = input from joystick");  //print "=input from joystick" next to the value
 Serial.print((joystickXVal+520)/10);       //print a from A1 calculated, scaled value
 Serial.println(" = output to servo");      //print "=output to servo" next to the value
 Serial.println() ;
 myservo.write((joystickXVal+520)/10);      //write the calculated value to the servo  


Darwin Dela Cruz

Darwin Dela Cruz

6 projects • 25 followers
Mabuhay! I'm a Filipino maker that build IoT, AI and Robotic projects. I'm also an developer that contributes in open source community.