Components and supplies
Arduino UNO
SG90 Micro-servo motor
Project description
Code
Code 2 as in video
arduino
1//This code is to use with dual axis fpv camera cradle that uses two servos, adding a joystick module 2//We control the position of the cradle by moving the analog stick, the cradle move to the direction where the stick is pointing 3//until the limits and stay there 4//Refer to surtrtech.com for more information 5 6#include <Servo.h> //Servos library and declaration 7 8Servo myservo1; 9Servo myservo2; 10 11int a,b,X,Y; //Variables needed later 12int YAxis = 1; //Declaring where the X axis and Y axis of the joystick pins are wired 13int XAxis = 0; //Of course analog inputs 14 15void setup() { 16 Serial.begin(9600); //Setting the Serial monitor baude rate and launching 17 pinMode(XAxis, INPUT); //Declaring the pin modes and servo pins 18 myservo1.attach(8); 19 pinMode(YAxis, INPUT); 20 myservo2.attach(9); 21} 22 23void loop() { 24 25 a=myservo1.read(); //Reading the previous servos positions is an important step so we can know where they should position next 26 b=myservo2.read(); 27 X=analogRead(XAxis);//Reading the joystick values 28 Y=analogRead(YAxis); 29 30 if(X>550){ //Here we didn't do any calibration so the joystick has three positions (Left|Resting|Right) 31 a=a-1; //it depends on the value we read we can know in which direction the stick is pointing and I left the resting position big actually it's just 1 value 32 myservo1.write(a); //we inject the new value 33 delay(50); //You can make the delay big or short or act on a=a-x to make big steps or short steps 34 } 35 if(X<450){ 36 a=a+1; //Here we did the opposit operation to move to the opposit direction 37 myservo1.write(a); 38 delay(50); 39 } 40 if(Y>600){ //Here we didn't do any calibration so the joystick has three positions (Up|Resting|Down) ditto 41 b=b+1; 42 myservo2.write(b); 43 delay(50); 44 } 45 if(Y<450){ 46 b=b-1; 47 myservo2.write(b); 48 delay(50); 49 }
Code 2 as in video
arduino
1//This code is to use with dual axis fpv camera cradle that uses two servos, adding a joystick module 2//We control the position of the cradle by moving the analog stick, the cradle move to the direction where the stick is pointing 3//until the limits and stay there 4//Refer to surtrtech.com for more information 5 6#include <Servo.h> //Servos library and declaration 7 8Servo myservo1; 9Servo myservo2; 10 11int a,b,X,Y; //Variables needed later 12int YAxis = 1; //Declaring where the X axis and Y axis of the joystick pins are wired 13int XAxis = 0; //Of course analog inputs 14 15void setup() { 16 Serial.begin(9600); //Setting the Serial monitor baude rate and launching 17 pinMode(XAxis, INPUT); //Declaring the pin modes and servo pins 18 myservo1.attach(8); 19 pinMode(YAxis, INPUT); 20 myservo2.attach(9); 21} 22 23void loop() { 24 25 a=myservo1.read(); //Reading the previous servos positions is an important step so we can know where they should position next 26 b=myservo2.read(); 27 X=analogRead(XAxis);//Reading the joystick values 28 Y=analogRead(YAxis); 29 30 if(X>550){ //Here we didn't do any calibration so the joystick has three positions (Left|Resting|Right) 31 a=a-1; //it depends on the value we read we can know in which direction the stick is pointing and I left the resting position big actually it's just 1 value 32 myservo1.write(a); //we inject the new value 33 delay(50); //You can make the delay big or short or act on a=a-x to make big steps or short steps 34 } 35 if(X<450){ 36 a=a+1; //Here we did the opposit operation to move to the opposit direction 37 myservo1.write(a); 38 delay(50); 39 } 40 if(Y>600){ //Here we didn't do any calibration so the joystick has three positions (Up|Resting|Down) ditto 41 b=b+1; 42 myservo2.write(b); 43 delay(50); 44 } 45 if(Y<450){ 46 b=b-1; 47 myservo2.write(b); 48 delay(50); 49 }
Code 1 as in video
arduino
1//This code is to use with dual axis fpv camera cradle that uses two servos, adding a joystick module 2//we control the position of the cradle by moving the analog stick, the cradle follows the joystick movements 3//Refer to surtrtech.com for more information 4 5#include <Servo.h> //Servos library and declaration 6 7Servo myservo1; 8Servo myservo2; 9 10int YAxis = 1; //Declaring where the X axis and Y axis of the joystick pins are wired 11int XAxis = 0; //Of course analog inputs 12 13void setup() { 14 Serial.begin(9600); //Setting the Serial monitor baude rate and launching 15 pinMode(XAxis, INPUT); //Declaring the pin modes and servo pins 16 myservo1.attach(8); 17 pinMode(YAxis, INPUT); 18 myservo2.attach(9); 19 20} 21void loop() { 22 int X=analogRead(XAxis); //Reading from the X axis potentiometer 23 X=X*0.1756; //Converting the range of the potentiometer from 0-1023 to 0-180 limits of the servo you can change them if you have a 360° servos 24 X=180-X;// This is used so the servo turn to exact position otherwise it will be inverted 25 myservo1.write(X); //After adapting we inject that value to the first servo 26 27 int Y=analogRead(YAxis);//Reading from the Y axis potentiometer 28 Y=Y*0.1466; //Here we did conversion that suits the servo limits so we went from 0-1023 to 0-150 29 myservo2.write(Y);//And we inject to our servo 30}
Downloadable files
Cradle servos wiring + Joystick
There is a top servo and bottom servo don't get them confused
Cradle servos wiring + Joystick
Cradle servos wiring + Joystick
There is a top servo and bottom servo don't get them confused
Cradle servos wiring + Joystick
Comments
Only logged in users can leave comments
SurtrTech
0 Followers
•0 Projects
Table of contents
Intro
61
0