Friday, June 25, 2021

Project 10: Arduino Robot Arm

 Project 10:  Arduino Robot Arm




Arm Logic 

Mode1: Robot Arm will move front down then up and move to left then open / close claw, and go back to middle and then go to right side and then open / close claw and then go back to middle again.
Mode2: Robot Arm will move front down, then pick an object and then move it up, and turn to left then open / close claw to drop the object, and move front down to pick object and then move it up and return to middle and drop it.





#include <Servo.h>
Servo middle, left, right, claw ;  // creates 4 "servo objects"
int  middlepin=11;  // orange attaches the Base servo
int  leftpin=10;   // green wire attaches the left servo
int  rightpin=9;   // gray wire attaches right servo
int  clawpin=6;   // yellow wire attaches the servo on pin 6 to the claw object
int pos = 0;    // variable to store the servo position
void setup() 
  Serial.begin(9600);
  /*
  middle.attach(leftpin);  // orange attaches the servo on pin leftpin to the middle object
  left.attach(rightpin);  // yellow wire attaches the servo on pin rightpin to the left object
  right.attach(clawpin);  // purple wire attaches the servo on pin  to the right object
  claw.attach(6);  // white wire attaches the servo on pin 6 to the claw object

   middle.attach(middlepin);  // orange attaches the servo on pin leftpin to the middle object
  left.attach(leftpin);  // yellow wire attaches the servo on pin rightpin to the left object
  right.attach(rightpin);  // purple wire attaches the servo on pin 9 to the right object
  claw.attach(clawpin);  // white wire attaches the servo on pin 6 to the claw object
*/
 
  // hand();
  //slowmove();
//right_left();
// right_left_Up();
 //right_left_front();
 //right_left_Up();

 //base();

 //right_left_front_dwon();
 //right_left_Up();
 //basefslow();
//newmove();
 

void slowmove()
{
   left.attach(leftpin);  // attaches the servo on pin 9 to the servo object
  right.attach(rightpin);  // attaches the servo on pin 9 to the servo object
  //left.write(180); 
  //right.write(0);  
 
  
  for (pos = 45; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    left.write(pos); 
   right.write(180-pos);  
    
    delay(15);                       // waits 15ms for the servo to reach the position
  }

   delay (50);
  left.detach();
  right.detach(); 
  
//  
//  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
//    myservo.write(pos);              // tell servo to go to position in variable 'pos'
//    delay(15);                       // waits 15ms for the servo to reach the position
//  }
}

void basefslow()
{
   // middle
  // right trun =0
  middle.attach(middlepin);  // attaches the servo on pin 9 to the servo object
   for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
     middle.write(90-pos);      
    delay(15);                       // waits 15ms for the servo to reach the position
  }
   delay(50); 
  middle.detach();
   hand();
   
  //back middle =90
  middle.attach(middlepin);  // attaches the servo on pin 9 to the servo objectclawV.write(90);  
  for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
     middle.write(pos);      
    delay(15);                       // waits 15ms for the servo to reach the position
  }
 // middle.write(90);  
  //delay (500);
  delay(50); 
  middle.detach();
 hand();
 
   // left trun=180
  middle.attach(middlepin);  // attaches the servo on pin 9 to the servo object
   for (pos = 90; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
     middle.write(pos);      
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  //middle.write(180);  
  delay (50);
  middle.detach();
 hand();
 
  //back middle =90
  middle.attach(middlepin);  // attaches the servo on pin 9 to the servo objectclawV.write(90);  
   for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
     middle.write(180-pos);      
    delay(15);                       // waits 15ms for the servo to reach the position
  }
//  middle.write(90);  
  delay (50);
  middle.detach();
   hand();
}

void newmove()
{
  right_left_front_dwon();
  hand();
  right_left_Up();
   // middle
  // left trun=180
  middle.attach(middlepin);  // attaches the servo on pin 9 to the servo object
   for (pos = 90; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
     middle.write(pos);      
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  //middle.write(180);  
  delay (50);
  middle.detach();
  
 hand();

 right_left_front_dwon();
 
  hand();
  right_left_Up();
  
  //back middle =90
  middle.attach(middlepin);  // attaches the servo on pin 9 to the servo objectclawV.write(90);  
   for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
     middle.write(180-pos);      
    delay(15);                       // waits 15ms for the servo to reach the position
  }
//  middle.write(90);  
  delay (50);
  middle.detach();
   hand();
 
  
}


void base()
{
   // middle
  // right trun =0
  middle.attach(middlepin);  // attaches the servo on pin 9 to the servo object
   middle.write(0);  
  delay (500);
  middle.detach();
   hand();
   
  //back middle =90
  middle.attach(middlepin);  // attaches the servo on pin 9 to the servo objectclawV.write(90);  
  middle.write(90);  
  delay (500);
  middle.detach();
 hand();
 
   // left trun
  middle.attach(middlepin);  // attaches the servo on pin 9 to the servo object
  middle.write(180);  
  delay (500);
  middle.detach();
 hand();
  //back middle 
  middle.attach(middlepin);  // attaches the servo on pin 9 to the servo objectclawV.write(90);  
  middle.write(90);  
  delay (500);
  middle.detach();
   hand();
}
void right_left()
{
  left.attach(leftpin);  // attaches the servo on pin 9 to the servo object
  right.attach(rightpin);  // attaches the servo on pin 9 to the servo object
  left.write(0); 
  right.write(90);  
  delay (500);
  left.detach();
  right.detach(); 
}


void right_left_front_dwon()
{
  left.attach(leftpin);  // attaches the servo on pin 9 to the servo object
  right.attach(rightpin);  // attaches the servo on pin 9 to the servo object
  left.write(50); 
  right.write(15);
 // left.write(180); 
//  right.write(90);    
  delay (500);
  left.detach();
  right.detach();
  delay (500); 
}

void right_left_front()
{
  left.attach(leftpin);  // attaches the servo on pin 9 to the servo object
  right.attach(rightpin);  // attaches the servo on pin 9 to the servo object
  left.write(180); 
  right.write(45);  
  delay (500);
  left.detach();
  right.detach(); 
}
void right_left_Up()
{
  left.attach(leftpin);  // attaches the servo on pin 9 to the servo object
  right.attach(rightpin);  // attaches the servo on pin 9 to the servo object
  left.write(0); 
  right.write(90);    // tell servo to go to position in variable 'pos'
  delay (500);
  left.detach();
  right.detach(); 
  delay (500);
}

void hand()
{
  // claw
  // open
  
  claw.attach(clawpin);  // attaches the servo on pin 9 to the servo object
  claw.write(0);  
  delay (700);
  claw.detach();
  
  //close
  
  claw.attach(clawpin);  // attaches the servo on pin 9 to the servo objectclawV.write(90);  
  claw.write(90);  
  delay (1000);
  claw.detach();

   delay (500);
   
}
void fullstep1()
{
left.attach(leftpin);  // attaches the servo on pin 9 to the servo object
right.attach(rightpin);  // attaches the servo on pin 9 to the servo object

left.write(60); 
//delay (300);
right.write(60);   // tell servo to go to position in variable 'pos'
delay (500);
left.detach();
right.detach(); 

// claw

// open
claw.attach(clawpin);  // attaches the servo on pin 9 to the servo object
claw.write(0);  
delay (500);
claw.detach();

//close
claw.attach(clawpin);  // attaches the servo on pin 9 to the servo objectclawV.write(90);  
claw.write(90);  
delay (500);
claw.detach();

left.attach(leftpin);  // attaches the servo on pin 9 to the servo object
left.write(135);  
delay (1500);
left.detach();

right.attach(rightpin);  // attaches the servo on pin 9 to the servo object
right.write(0);  
delay (1500);
right.detach();
}

void loop() 
 //newmove();
 //delay (10000);
}



No comments:

Post a Comment