Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
jegatheesan
Published © GPL3+

BT Mobile Ctrl Trunk Robotic Arm Using String

Trunk Robotic arm is a art in modern robotics. It can able to spin and work like artistic.

IntermediateFull instructions provided2 days2,480
BT Mobile Ctrl Trunk Robotic Arm Using String

Things used in this project

Story

Read more

Code

Trunkarmmobile.ino

Arduino
For testing trunk arm using mobile tilt control
#include <Servo.h> 
String inputString = "";         
boolean stringComplete = false; 

String Char1;

int stl1;
int stl2;
int stl;

int Rotx=90;
int Roty=90;

Servo myservo3;
Servo myservo5;
Servo myservo6;
Servo myservo9; 
int pos = 0;
int pos1 = 0;
int pos2 = 0;
int pos3 = 0;
int pos4 = 0;

int Npos1 = 0;
int Npos3 = 0;


#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 4); 


void setup() {
//  Serial.begin(9600);
  inputString.reserve(200);
    mySerial.begin(9600);    
//    inputString=">3,400,348.57266,-5.5952916,52.7636";
    inputString="";
    
  myservo3.attach(3);
  myservo5.attach(5);
  myservo6.attach(6);
  myservo9.attach(9);
  delay(100);
    myservo3.write(90);
    myservo5.write(90);
    myservo6.write(90);
    myservo9.write(90);
  delay(15);  
  pos1=90;
  pos2=90;
  pos3=90;
  pos4=90;    
}

void loop() {
   while (mySerial.available()) {
    char inChar = (char)mySerial.read();
    inputString += inChar;
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
  
  if (stringComplete) {
//    mySerial.end();
    extractpos();    
//    Serial.println(inputString);
    // clear the string:
    inputString = "";
    stringComplete = false;
    Npos1=90-Rotx;
    Npos3=90-Roty;
    if (Npos1 <= 0)
    {
      Npos1=0;
    }else if (Npos1 >= 180)
    {
      Npos1=180;
    }

    if (Npos3 <= 0)
    {
      Npos3=0;
    }else if (Npos3 >= 180)
    {
      Npos3=180;
    }
    
  if (pos1<(Npos1-5))
  {
    for(pos1=pos1;pos1<Npos1;pos1+=1)
    {
      myservo3.write(pos1);
      pos2=180-pos1;
      myservo5.write(pos2);
      delay(15);
    }      
//    Serial.println("1");
  }else if (pos1>(Npos1+5))
  {
    for(pos1 = pos1; pos1>Npos1; pos1-=1)      
    {                                
      myservo3.write(pos1);
      pos2=180-pos1;
      myservo5.write(pos2);
      delay(15);    
    }
//    Serial.println("2");    
  } 

  if (pos3<(Npos3-5))
  {
    for(pos3=pos3;pos3<Npos3;pos3+=1)
    {
      myservo6.write(pos3);
      pos4=180-pos3;
      myservo9.write(pos4);
      delay(15);
    }      
//    Serial.println("3");        
  }else if (pos3>(Npos3+5))
  {
    for(pos3 = pos3; pos3>Npos3; pos3-=1)      
    {                                
      myservo6.write(pos3);
      pos4=180-pos3;
      myservo9.write(pos4);
      delay(15);    
    }    
//    Serial.println("4");        
  }
//    Serial.print(pos1);
//    Serial.print("-");
//    Serial.print(pos2);
//    Serial.print("-");
//    Serial.print(pos3);
//    Serial.print("-");
//    Serial.println(pos4);
//    mySerial.begin(9600);
  }
}


void extractpos(){
    stl1 = inputString.indexOf(",");
    if(stl1>0) 
    {
      Char1=inputString.substring(0,stl1);
      if (Char1 == ">3")
      {
        stl2 = inputString.indexOf(",",stl1+1);
        if (stl2>0)
        {
          Char1=inputString.substring(stl1+1,stl2);
//          Serial.println(Char1);          
          stl1=stl2;
            stl2 = inputString.indexOf(",",stl1+1);
            if (stl2>0)
            {
              Char1=inputString.substring(stl1+1,stl2);
//              Serial.println(Char1);          
              stl1=stl2;
                stl2 = inputString.indexOf(",",stl1+1);
                if (stl2>0)
                {
                  Char1=inputString.substring(stl1+1,stl2);
                  Rotx=Char1.toInt();
//                  Serial.println(Char1);          
                  stl1=stl2;                  
                  stl=inputString.length();
                  Char1=inputString.substring(stl1+1,stl);
                  Roty=Char1.toInt();                  
//                  Serial.println(Char1);          
//                  Serial.println(Rotx);
//                  Serial.println(Roty);                  
                }              
            }                    
        }
      }
    }
}

Armrobotics.ino

Arduino
Flexible arm robotic action
#include <Servo.h> 
 
Servo myservo3;
Servo myservo5;
Servo myservo6;
Servo myservo9; 
Servo myservo10; 
int pos = 0;    // variable to store the servo position 

int pos1 = 0;    // variable to store the servo position 
int pos2 = 0;
int pos3 = 0;
int pos4 = 0;
int pos5 = 0;
 
void setup() 
{ 
  myservo3.attach(3);
  myservo5.attach(5);
  myservo6.attach(6);
  myservo9.attach(9);
  myservo10.attach(10);  
  delay(100);
    myservo3.write(90);
    myservo5.write(90);
    myservo6.write(90);
    myservo9.write(90);
    myservo10.write(90);    
  delay(15);  
  
  pos1=90;
  pos2=90;
  pos3=90;
  pos4=90;
  pos5=10;
  for(pos1=90;pos1<=180;pos1+=1)
  {
    myservo3.write(pos1);
    pos2=180-pos1;
    myservo5.write(pos2);
    delay(15);
  }  
  for(pos3=90;pos3<=180;pos3+=1)
  {
    myservo6.write(pos3);
    pos4=180-pos3;
    myservo9.write(pos4);
    delay(15);
  }
  
  for(pos5 = 10; pos5 <= 60; pos5 += 1) 
  {                                   
    myservo10.write(pos5);            
    delay(15);                       
  }   
} 
 
void loop() 
{   
  for(pos1 = 180; pos1>=90; pos1-=1)    
  {                                
    myservo3.write(pos1);
    pos2=180-pos1;
    myservo5.write(pos2);
    delay(15);    
  }  

  for(pos3 = 180; pos3>=90; pos3-=1)    
  {                                
    myservo6.write(pos3);
    pos4=180-pos3;
    myservo9.write(pos4);
    delay(15);    
  } 
 
  delay(1000);
  
  for(pos3=90;pos3<=180;pos3+=1)
  {
    myservo6.write(pos3);
    pos4=180-pos3;
    myservo9.write(pos4);
    delay(15);
    
    pos1=180-pos3;
    myservo3.write(pos1);
    pos2=180-pos1;
    myservo5.write(pos2);
    delay(15);    
  }
  
//  for(pos1 = 90; pos1>=0; pos1-=1)    
//  {                                
//    myservo3.write(pos1);
//    pos2=180-pos1;
//    myservo5.write(pos2);
//    delay(15);    
//  }  
  
  for(pos5 = 10; pos5 <= 60; pos5 += 1) 
  {                                   
    myservo10.write(pos5);            
    delay(15);                       
  }    
  
  for(pos3 = 180; pos3>=0; pos3-=1)    
  {                                
    myservo6.write(pos3);
    pos4=180-pos3;
    myservo9.write(pos4);
    delay(15);    
  }
  
  for(pos1=0;pos1<=180;pos1+=1)
  {
    myservo3.write(pos1);
    pos2=180-pos1;
    myservo5.write(pos2);
    delay(15);
  }  
  for(pos3=0;pos3<=180;pos3+=1)
  {
    myservo6.write(pos3);
    pos4=180-pos3;
    myservo9.write(pos4);
    delay(15);
  }    
  
 
   for(pos5 = 60; pos5>=10; pos5-=1)
  {                                
    myservo10.write(pos5);
    delay(15);
  }  
} 

Credits

jegatheesan

jegatheesan

18 projects • 67 followers
Simply A Mechatronics Lover.

Comments