Devices & Components
Arduino Uno Rev3
joystick
Jumper wires (generic)
9V battery (generic)
SG90 Micro-servo motor
Battery, 9 V
Breadboard (generic)
Breadboard (generic)
joystick
Jumper wires (generic)
SG90 Micro-servo motor
Hardware & Tools
Hot glue gun (generic)
Software & Tools
Arduino IDE
Project description
Code
code
c_cpp
this is the code for joystick controlling servo
1#include<Servo.h> 2const int x=A0; 3const int y=A1; 4Servo servo; 5 6void setup() { 7 pinMode(x,INPUT); 8 pinMode(y,INPUT); 9 servo.attach(8); 10 Serial.begin(9600); 11 12} 13 14void loop() { 15 int xval=analogRead(x); 16 int yval=analogRead(y); 17 18 Serial.println(yval); 19 if( yval<100){ 20 servo.write(90); 21 } 22 else if(yval>900){ 23 servo.write(180); 24} 25else{ 26 servo.write(0); 27} 28} 29
code
c_cpp
this is the code for joystick controlling servo
1#include<Servo.h> 2const int x=A0; 3const int y=A1; 4Servo servo; 5 6void 7 setup() { 8 pinMode(x,INPUT); 9 pinMode(y,INPUT); 10 servo.attach(8); 11 Serial.begin(9600); 12 13} 14 15void 16 loop() { 17 int xval=analogRead(x); 18 int yval=analogRead(y); 19 20 Serial.println(yval); 21 22 if( yval<100){ 23 servo.write(90); 24 } 25 else if(yval>900){ 26 servo.write(180); 27} 28else{ 29 30 servo.write(0); 31} 32} 33
Downloadable files
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
The connections for joystick with servo

Comments
Only logged in users can leave comments