Verification error message

Hello everyone! I am new to Arduino and recently built a robotic arm. When verifying my code, I received an error message (The error code is in the attachment). How can I make the code work?

#include <Servo.h>  
Servo myservoA.attach 3;  //control waist (a) port number is 3  
Servo myservoB.attach 5;  //control shoulder (b) port is 5
Servo myservoC.attach 6;  //control forearm (c) is 6
Servo myservoD.attach 9;  // Control Forearm rotation (D) port number is 9
Servo myservoE.attach 10; // Control wrist(E)port number is 10 wrist
Servo myservoF.attach 11; // Control wrist rotation (F) port number is 11
int i,pos,myspeed,myshow;
int sea,seb,sec,sed,see,sef;
static int v=0;

String mycommand="";    /// Serial capture   #auto: automatic operation  #com: computer serial port control  #stop: standstill
static int mycomflag=2; // #auto:2 automatic operation  , #com: 1  computer serial port control    #stop:0  standstill 


void myservosetup()  //initialization
{
   sea=myservoA.read();
   seb=myservoB.read();
   sec=myservoC.read();
   sed=myservoD.read();
   see=myservoE.read();
   sef=myservoF.read();
   
   myspeed=500;
   for(pos=0;pos<=myspeed;pos+=1)
   {
    myservoA.write(int(map(pos,1,myspeed,sea,66)));
    myservoB.write(int(map(pos,1,myspeed,seb,60)));
    myservoC.write(int(map(pos,1,myspeed,sec,20)));
    myservoD.write(int(map(pos,1,myspeed,sed,60)));
    myservoE.write(int(map(pos,1,myspeed,see,90)));
    myservoF.write(int(map(pos,1,myspeed,sef,90)));    
    delay(1);
   }
}

void setup() 
{ 
  pinMode(13,INPUT);
  pinMode(12,INPUT);  
  Serial.begin(9600);
  myshow=0;
  mycomflag=2;         // the  ARM default  state: 2 automatic operation
  myservoA.attach(3);  //  Control waist (A) port number is   3    
  myservoB.attach(5);  //  Control lorearm(B)port number is 5    
  myservoC.attach(6);  //  Control  Forearm(C)port number is 6
  myservoD.attach(9);  // Control Forearm rotation (D) port number is 9
  myservoE.attach(10); // Control wrist(E)port number is 10 wrist
  myservoF.attach(11); // Control wrist rotation (F) port number is 11
  
  myservoA.write(66);
  myservoB.write(60);
  myservoC.write(20);
  myservoD.write(60);
  myservoE.write(90);
  myservoF.write(90);    

}

void loop() 
{ 
  while (Serial.available() > 0)  
    {
        mycommand += char(Serial.read());
        delay(2);
    }
    if (mycommand.length() > 0)
    {
        if(mycommand=="#auto")
        {
          mycomflag=2;
          Serial.println("auto station");
          mycommand="";
        }
        if(mycommand=="#com")
        {
          mycomflag=1;
          Serial.println("computer control station");
          mycommand="";
          myservosetup();
        }
        if(mycommand=="#stop")
        {
          mycomflag=0;
          Serial.println("stop station");
          mycommand="";
        }
        
    }
  
  
  if(mycomflag==1)  //if  read myconflag==1 means computer serial port control
  {      
 
   for(int m=0;m<mycommand.length();m++) // 
  {
    char ch = mycommand[m];   //Read serial data
    switch(ch)
    {
      case '0'...'9':
      v = v*10 + ch - '0';   //Character conversion to decimal
      break;
      
      
      
      case 'a':             //If you post data with a, it means that the first servo data, such as serial port 85a
      if(v >= 5 || v <= 175 ) myservoA.write(v); 
      v = 0;
      break;

      case 'b':   //If you post data with b, it means that the second servo data, such as serial port 85b

      myservoB.write(v);   //For setting the steering angle of rotation of the statement can be set angle range is 0 ° to 180 °, 
                           // "V" get the value of the input and change the angle, such as 90b is 90°
      v = 0;
      break;
      case 'c':   
      if(v >= 20 ) myservoC.write(v);   
      v = 0;
      break;
      case 'd':  
      myservoD.write(v);   
      v = 0;
      break;
      case 'e':  
      myservoE.write(v);   
      v = 0;
      break;
      case 'f':  
      myservoF.write(v);   
      v = 0;
      break;
    }
   
    }  
   mycommand="";
  }  // end if(mycomflag=2)
  
  if(mycomflag==2)  //if mycomflag==2  means automatic operation
  {    
   delay(3000); 
   //Serial.println("auto station"); 
   myservosetup();
   myspeed=600;
    for(pos = 0; pos <=myspeed; pos += 1)  
  {                                
    myservoA.write(int(map(pos,1,myspeed,66,10))); //Let A rotation from 66 degrees to 90 degrees (angle can be modified)1
    myservoB.write(int(map(pos,1,myspeed,60,100))); //Let B rotation from 60 degrees to 100 degrees (angle can be modified)
    delay(1);                       
  }
   delay(1000);
   myspeed=500;
  for(pos = 0; pos <=myspeed; pos += 1)  
  {                                
    myservoC.write(int(map(pos,1,myspeed,20,40))); // 30-65
    myservoD.write(int(map(pos,1,myspeed,60,100))); //  4
    myservoE.write(int(map(pos,1,myspeed,90,40))); //
    delay(1);                       
   }
   delay(1000);
  myspeed=1000;
  for(pos = 0; pos <=myspeed; pos += 1)  
  {                                
    myservoB.write(int(map(pos,1,myspeed,100,120))); // 
//    myservoC.write(int(map(pos,1,myspeed,40,50))); //
    delay(1);                       
   }
     delay(1000);
   myspeed=500;
  for(pos = 0; pos <=myspeed; pos += 1)  
  {                                
//    myservoC.write(int(map(pos,1,myspeed,50,40))); // 
    myservoD.write(int(map(pos,1,myspeed,100,70))); //
    myservoE.write(int(map(pos,1,myspeed,40,90)));
    myservoF.write(int(map(pos,1,myspeed,90,50)));
    delay(1);                       
   }   
   delay(1000);
   myspeed=1000;
  for(pos = 0; pos <=myspeed; pos += 1)  
  {                                
    myservoA.write(int(map(pos,1,myspeed,10,100))); // 
    myservoF.write(int(map(pos,1,myspeed,50,110)));    
    delay(1);                       
   }  
    delay(1000);
    myspeed=500;
    for(pos = 0; pos <=myspeed; pos += 1)  
  {                                
    myservoA.write(int(map(pos,1,myspeed,100,50))); //
    myservoC.write(int(map(pos,1,myspeed,40,50))); // 
    myservoB.write(int(map(pos,1,myspeed,120,70))); //
    myservoE.write(int(map(pos,1,myspeed,90,60))); //
    delay(1);                       
  } 
  }
  
  if(mycomflag==0) // Static state
  {
   myservosetup();
  }
}

The error code is in the attachment

arduinoerror.txt (5.91 KB)

Before setup, declare the Servo objects:

Servo myservoA;

and so on.

Then call the attach method of each of those servos in setup().

Servo.attach(3);

That's because the code is completely wrong.

Did you mean something like:

Servo myServoA;
...

void setup ()
{
  myServoA.attach (3) ;
  ...

Did you consider searching for example Servo code?

(1) You have made the newbie mistake (a common one) of trying to do too much too soon.

(2) When you are tempted to suffix your variable names with numbers or letters, it is time to learn about using arrays.

(3)

Servo myservoA.attach 3;  //control waist (a) port number is 3

The way to declare myservoA is

Servo myservoA;

and the way to attach is to do this inside the setup() function (as you did):

myservoA.attach(3) ;

Notice the separation between declaration and attach. Also notice the use of parentheses.

(4) Do the same for all of your servos.

(5) In this

static int mycomflag=2;

the static declaration is harmless but unnecessary. The following would have been sufficient:

int mycomflag=2;

(6) Using String on an Arduino is considered a poor idea in the long run.

(7) I do not know that these ideas will fix all of your errors, but it is a start. The next time that you want to post code and error messages...

To post code and/or error messages:

  1. Use CTRL-T in the Arduino IDE to autoformat your complete code.
  2. Paste the complete autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.
  3. Paste the complete error message between code tags (the </> button)
    so that we can easily see and deal with your messages.
  4. If you already posted without code tags, you may add the code tags by
    editing your post. Do not change your existing posts in any other way.
    You may make additional posts as needed.

Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.

If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a clear photograph of the wiring.

Good Luck!

Thank you all for the responses! I am still receiving an error code after fixing the problems previously noted (attachment)

#include <Servo.h>  

Servo myservoA;

void setup ()

myservoA.attach(3) ;  //control waist (a) port number is 3  
Servo myServoB;

void setup ()


  myServoB.attach (5) ;  //control shoulder (b) port is 5
Servo myServoC;

void setup ()

  myServoC.attach (6) ;Servo myservoC.attach 6;  //control forearm (c) is 6
Servo myServoD;

void setup ()

  myServoD.attach (9) ;Servo myservoD.attach 9;  // Control Forearm rotation (D) port number is 9
Servo myServoE;

void setup ()

  myServoE.attach (10) ;Servo myservoE.attach 10; // Control wrist(E)port number is 10 wrist
Servo myServoF;

void setup ()

  myServoF.attach (11) ;Servo myservoF.attach 11; // Control wrist rotation (F) port number is 11
int i,pos,myspeed,myshow;
int sea,seb,sec,sed,see,sef;
int v=0;

String mycommand="";    /// Serial capture   #auto: automatic operation  #com: computer serial port control  #stop: standstill
int mycomflag=2; // #auto:2 automatic operation  , #com: 1  computer serial port control    #stop:0  standstill 


void myservosetup()  //initialization
{
   sea=myservoA.read();
   seb=myservoB.read();
   sec=myservoC.read();
   sed=myservoD.read();
   see=myservoE.read();
   sef=myservoF.read();
   
   myspeed=500;
   for(pos=0;pos<=myspeed;pos+=1)
   {
    myservoA.write(int(map(pos,1,myspeed,sea,66)));
    myservoB.write(int(map(pos,1,myspeed,seb,60)));
    myservoC.write(int(map(pos,1,myspeed,sec,20)));
    myservoD.write(int(map(pos,1,myspeed,sed,60)));
    myservoE.write(int(map(pos,1,myspeed,see,90)));
    myservoF.write(int(map(pos,1,myspeed,sef,90)));    
    delay(1);
   }
}

void setup() 
{ 
  pinMode(13,INPUT);
  pinMode(12,INPUT);  
  Serial.begin(9600);
  myshow=0;
  mycomflag=2;         // the  ARM default  state: 2 automatic operation
  myservoA.attach(3);  //  Control waist (A) port number is   3    
  myservoB.attach(5);  //  Control lorearm(B)port number is 5    
  myservoC.attach(6);  //  Control  Forearm(C)port number is 6
  myservoD.attach(9);  // Control Forearm rotation (D) port number is 9
  myservoE.attach(10); // Control wrist(E)port number is 10 wrist
  myservoF.attach(11); // Control wrist rotation (F) port number is 11
  
  myservoA.write(66);
  myservoB.write(60);
  myservoC.write(20);
  myservoD.write(60);
  myservoE.write(90);
  myservoF.write(90);    

}

void loop() 
{ 
  while (Serial.available() > 0)  
    {
        mycommand += char(Serial.read());
        delay(2);
    }
    if (mycommand.length() > 0)
    {
        if(mycommand=="#auto")
        {
          mycomflag=2;
          Serial.println("auto station");
          mycommand="";
        }
        if(mycommand=="#com")
        {
          mycomflag=1;
          Serial.println("computer control station");
          mycommand="";
          myservosetup();
        }
        if(mycommand=="#stop")
        {
          mycomflag=0;
          Serial.println("stop station");
          mycommand="";
        }
        
    }
  
  
  if(mycomflag==1)  //if  read myconflag==1 means computer serial port control
  {      
 
   for(int m=0;m<mycommand.length();m++) // 
  {
    char ch = mycommand[m];   //Read serial data
    switch(ch)
    {
      case '0'...'9':
      v = v*10 + ch - '0';   //Character conversion to decimal
      break;
      
      
      
      case 'a':             //If you post data with a, it means that the first servo data, such as serial port 85a
      if(v >= 5 || v <= 175 ) myservoA.write(v); 
      v = 0;
      break;

      case 'b':   //If you post data with b, it means that the second servo data, such as serial port 85b

      myservoB.write(v);   //For setting the steering angle of rotation of the statement can be set angle range is 0 ° to 180 °, 
                           // "V" get the value of the input and change the angle, such as 90b is 90°
      v = 0;
      break;
      case 'c':   
      if(v >= 20 ) myservoC.write(v);   
      v = 0;
      break;
      case 'd':  
      myservoD.write(v);   
      v = 0;
      break;
      case 'e':  
      myservoE.write(v);   
      v = 0;
      break;
      case 'f':  
      myservoF.write(v);   
      v = 0;
      break;
    }
   
    }  
   mycommand="";
  }  // end if(mycomflag=2)
  
  if(mycomflag==2)  //if mycomflag==2  means automatic operation
  {    
   delay(3000); 
   //Serial.println("auto station"); 
   myservosetup();
   myspeed=600;
    for(pos = 0; pos <=myspeed; pos += 1)  
  {                                
    myservoA.write(int(map(pos,1,myspeed,66,10))); //Let A rotation from 66 degrees to 90 degrees (angle can be modified)1
    myservoB.write(int(map(pos,1,myspeed,60,100))); //Let B rotation from 60 degrees to 100 degrees (angle can be modified)
    delay(1);                       
  }
   delay(1000);
   myspeed=500;
  for(pos = 0; pos <=myspeed; pos += 1)  
  {                                
    myservoC.write(int(map(pos,1,myspeed,20,40))); // 30-65
    myservoD.write(int(map(pos,1,myspeed,60,100))); //  4
    myservoE.write(int(map(pos,1,myspeed,90,40))); //
    delay(1);                       
   }
   delay(1000);
  myspeed=1000;
  for(pos = 0; pos <=myspeed; pos += 1)  
  {                                
    myservoB.write(int(map(pos,1,myspeed,100,120))); // 
//    myservoC.write(int(map(pos,1,myspeed,40,50))); //
    delay(1);                       
   }
     delay(1000);
   myspeed=500;
  for(pos = 0; pos <=myspeed; pos += 1)  
  {                                
//    myservoC.write(int(map(pos,1,myspeed,50,40))); // 
    myservoD.write(int(map(pos,1,myspeed,100,70))); //
    myservoE.write(int(map(pos,1,myspeed,40,90)));
    myservoF.write(int(map(pos,1,myspeed,90,50)));
    delay(1);                       
   }   
   delay(1000);
   myspeed=1000;
  for(pos = 0; pos <=myspeed; pos += 1)  
  {                                
    myservoA.write(int(map(pos,1,myspeed,10,100))); // 
    myservoF.write(int(map(pos,1,myspeed,50,110)));    
    delay(1);                       
   }  
    delay(1000);
    myspeed=500;
    for(pos = 0; pos <=myspeed; pos += 1)  
  {                                
    myservoA.write(int(map(pos,1,myspeed,100,50))); //
    myservoC.write(int(map(pos,1,myspeed,40,50))); // 
    myservoB.write(int(map(pos,1,myspeed,120,70))); //
    myservoE.write(int(map(pos,1,myspeed,90,60))); //
    delay(1);                       
  } 
  }
  
  if(mycomflag==0) // Static state
  {
   myservosetup();
  }
}

Because of the maximum word limit, I have to attach the error message as an attachment again.

I will also be taking a look at the example servo code shortly.

error message.txt (5.84 KB)

I have 6 servo motors, but will only be using 5 of them.

Yes, but there is only one setup() function, and it MUST be defined using C/C++ syntax, not the way that you have it.

All of the myServoX.attach(...) ; calls should be in the same, one, and only setup() function.

Look at an example to see how the setup() function is properly defined. If you cannot set up one servo properly, how are you going to set up five or six?

Simplify, simplify, simplify!

If it makes you feel better, the set up for each servo could be in a different function that is called from setup(), BUT...
... each function MUST have a different name and "setup" must NOT be any of them!

When you are tempted to suffix variable names with numbers or letters, it is time to learn about arrays.

I didn't write the code, I found it. I thought it would work as is, and it isn't and now I am trying to get it to work. The robotic arm it is for is similar to the one I built. Eventually I want to use the code as a base to get the arm to do what I want it to do. Here is the webiste I got it from: DIY 6-Axis Servos Control Palletizing Robot Arm Model for Arduino UNO MEGA2560 - [[:Template:SainSmart Wiki]]

I have taken a look at many open source robotic arms. In every comment section, there are people begging for the source code, so it seems like a common problem. This was pretty much the only thing I was able to find.