Devices & Components
Arduino Uno Rev3
Popsicle stick
cardboard
Male/Female Jumper Wires
Analog joystick (Generic)
RobotGeek Continuous Rotation Servo
Solderless Breadboard Full Size
Hardware & Tools
Hot glue gun
Software & Tools
Arduino IDE
Project description
Code
Arduino code
arduino
1//www.youtube.com/Electronics is Fun// 2//www.facebook.com/Electronics is Fun// 3//copyright by MOHD SOHAIL// 4 5 6#include <Servo.h> 7 8//Servo objects created to control the servos 9Servo myServo1; 10Servo myServo2; 11 12int servo1 = 3; //Digital PWM pin used by the servo 1 13int servo2 = 5; //Digital PWM pin used by the servo 2 14int joyX = 0; //Analog pin to which the joystick (X) is connected 15int joyY = 1; //Analog pin to which the joystick (Y) is connected 16 17void setup(){ 18 myServo1.attach(servo1); 19 myServo2.attach(servo2); 20} 21 22void loop(){ 23 24 int valX = analogRead(joyX); //Read the joystick X value (value between 0 and 1023) 25 int valY = analogRead(joyY); //Read the joystick Y value (value between 0 and 1023) 26 27 valX = map(valX, 0, 1023, 10, 170); //Scale the joystick X value to use it with the servo 28 valY = map(valY, 0, 1023, 10, 170); //Scale the joystick X value to use it with the servo 29 30 //Sets the servo position according to the scaled values. 31 myServo1.write(valX); 32 myServo2.write(valY); 33 34 delay(5); 35} 36
Downloadable files
Circuit Diagram
Circuit Diagram

Circuit Diagram
Circuit Diagram

Comments
Only logged in users can leave comments