DKVDH
Published © GPL3+

Joystick Servo Cradle

This project is a servo cradle controlled by a joystick.

BeginnerFull instructions provided804
Joystick Servo Cradle

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×2
2-Axis FPV Camera Cradle Head Kit with Dual Servo Gear for Robot R/C Car
×1
Analog joystick (Generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor

Story

Read more

Code

Arduino_Servo_Joystick.ino

C/C++
Upload to Uno
#include <Servo.h>
#define SERVO_PIN 9 
#define SERVO_PIN 10
#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
#define YJOY_PIN A0                  //Y axis reading from joystick will fo into analog pin A0
Servo servoX;
Servo servoY;
void setup()
{
 Serial.begin(9600);
 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)
 servoY.attach(9);
 servoX.attach(10);
}
 
void loop()
{
 delay(200);                    
 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() ;
 servoX.write((joystickXVal+520)/10);      //write the calculated value to the servo 

 delay(200);
 int joystickYVal = analogRead(YJOY_PIN);
 Serial.print(joystickYVal);                //print the value from A0
 Serial.println(" = input from joystick");  //print "=input from joystick" next to the value
 Serial.print((joystickYVal+520)/10);       //print a from A0 calculated, scaled value
 Serial.println(" = output to servo");      //print "=output to servo" next to the value
 Serial.println() ;
 servoY.write((joystickYVal+520)/10);       //write the calculated value to the servo 
}

Credits

DKVDH
6 projects • 3 followers

Comments