We are hosting Hackster Cafe: Open Hardware Summit. Watch now!
robot-maker
Published © GPL3+

Using joystick to control a micro servo

The project is great and easy for beginners as it uses 2 simple components: a joystick and servo motor

IntermediateProtip152
Using joystick to control a micro servo

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
joystick
×1
joystick
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Battery, 9 V
Battery, 9 V
×1
9V battery (generic)
9V battery (generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

The connections for joystick with servo

sorry for the abnormal image of the joystick as i did not find the component in the parts of fritzing and also i don't know much about editing so I did my best for making it easy to understand but if anyone has some problem in understanding please feel free to comment and I will surely answer

Code

code

C/C++
this is the code for joystick controlling servo
#include<Servo.h>
const int x=A0;
const int y=A1;
Servo servo;

void setup() {
 pinMode(x,INPUT);
 pinMode(y,INPUT);
 servo.attach(8);
 Serial.begin(9600);

}

void loop() {
 int xval=analogRead(x);
 int yval=analogRead(y);

 Serial.println(yval);
 if( yval<100){
  servo.write(90);
 }
 else if(yval>900){
 servo.write(180);
}
else{
  servo.write(0);
}
}

Credits

robot-maker
0 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.