0% found this document useful (0 votes)
2 views

Arduino with Servo Motor

Uploaded by

manojdhawan2017
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Arduino with Servo Motor

Uploaded by

manojdhawan2017
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment-1

Aim: Controlling actuators through Serial Monitor. Creating different led patterns
and controlling them using push button switches. Controlling servo motor with the
help of joystick.

Circuit Diagram

The hardware part of this project is very easy to make. First, connect the joystick
module with the Arduino. The connections for the joystick module and the Arduino
are as follows:

 Connect the VCC on the joystick module with the 5V pin on the Arduino
 Connect the GND pin on the joystick module with the GND on the Arduino
 Connect the VER pin on the joystick module with the A0 on the Arduino
 Connect the HOR pin on the joystick module with the A1 on the Arduino

After that, connect the servo motors with the Arduino. The connections for servo
motors with Arduino are as follows:

 Connect the black wire on both the servo motors with the GND on the Arduino
 Connect the red wire on both the servo motors with the 5V pin on the Arduino
 Connect the yellow wire on the first motor with pin 8 on the Arduino
 Connect the yellow wire on the second motor with pin 9 on the Arduino

2
Working Procedure-When the joystick module moves in the horizontal or in the vertical direction, it gives us values from 0 to
1023. So we can apply a condition in the code that if the value is less than 300 or greater than 700, then the servos will move.
When the joystick is moved in the horizontal direction, the first servo will move towards right or left and upon moving the
joystick in the vertical direction, the second servo will move towards the right or left.

#include if (initial_position< 10) { } else{ initial_position = initial_position - 20;


servo1.write (
Servo servo1;
initial_position ) ; delay (100) ; } } if (x_pos> 700){
Servo servo2;
if (initial_position> 180)
int x_key = A1;
{
int y_key = A0;
}
int x_pos;
else{
int y_pos;
initial_position = initial_position + 20;
int servo1_pin = 8;
servo1.write ( initial_position ) ;
int servo2_pin = 9;
delay (100) ;
int initial_position = 90;
}
int initial_position1 = 90;
}
void setup ( ) {
if (y_pos<300){
Serial.begin (9600) ;
if (initial_position1 < 10) { } else{ initial_position1 = initial_position1 - 20;
servo1.attach (servo1_pin ) ; servo2.write

servo2.attach (servo2_pin ) ; ( initial_position1 ) ; delay (100) ; } } if (y_pos> 700){

servo1.write (initial_position); if (initial_position1 > 180)

servo2.write (initial_position1); {

pinMode (x_key, INPUT) ; }

pinMode (y_key, INPUT) ; else{

} initial_position1 = initial_position1 + 20;

void loop ( ) { servo2.write ( initial_position1 ) ;

x_pos = analogRead (x_key) ; delay (100) ;

y_pos = analogRead (y_key) ; }

if (x_pos<300){ }

You might also like