You are on page 1of 2

#include <Servo.

h>
Servo myservo1; //Servo Shoulder Vertical Movement
Servo myservo2; //Servo Shoulder horizontal Movement
Servo myservo3; //Elbow Movement
Servo myservo4; //Gripper Movement
void setup()
{
Serial1.begin(9600);
myservo1.attach(9); //Attach Shoulder Vertical Movement Control Signal Pin To
9
myservo2.attach(10); //Attach Shoulder Horizontal Control Signal Pin To 10
myservo3.attach(3); //Attach Elbow Movement Control Signal Pin To 3
myservo4.attach(5); //Attach Gripper Movement Control Signal Pin To 5
}
void loop()
{
if(Serial1.available()>0) //Check for any data in Serial Port
{
byte con = Serial1.read(); //Read serial data and store it in con
if(con > 0)
{
if(con < 50)
{
con = (180*con)/50; //Decrypt the data obtained
myservo1.write(con); //Write the data to myservo1
delay(15);
}
}
if(con > 50)
{
if(con < 100)
{
con = (180*(con-50))/50; //Decrypt the data obtained
myservo2.write(con); //Write the data to myservo2
delay(15);
}
}
if(con > 100)
{
if(con < 150)
{
con = (180*(con-100))/50; //Decrypt the data obtained
myservo3.write(con); //Write the data to myservo3
delay(15);
}
}
if(con > 150)
{
if(con < 200)
{
con = (180*(con-150))/50; //Decrypt the data obtained
if(con<20)
{
myservo4.write(180); //Write the data to myservo4
delay(15);
}
if(con>20)
{
myservo4.write(60);
delay(15);
}
}
}
}
}

You might also like