Unable To Use Multiple Servos On Arduino

I am in the final stages of creating an ‘Inmoov Robotic Hand’. It’s a 3D printed robotic hand controlled by flex sensors which a certain servo reenacts.
A DC power supply is connected to the Arduino to provide power to all servos (set on 6v), and the voltage from the Arduino itself powers the flex sensors. All works well, other than if multiple flex sensors are flexed. This causes multiple servos to move (e.g. 3 Servos from 3 Flexed Sensors); when this happens, the system stops working and bugs out. I think it is due to the drawn current from the multiple servos acting at the same time.

Here’s my code:

#include <Servo.h> 
 
int pos1 = 0; //Set first servo to an initial position of 0
int pos2 = 0; //Set second servo to an initial position of 0
int pos3 = 0; //Set third servo to an initial position of 0
int pos4 = 0; //Set fourth servo to an initial position of 0
int pos5 = -300; //Set fifth servo to an initial position of 0

Servo myservo;  // create 1st servo object to control a servo 
                
Servo myservo01; // create 2nd servo object to control a servo 

Servo myservo02; // create 3rd servo object to control a servo 

Servo myservo03; // create 4th servo object to control a servo 

Servo myservo04; // create 5th servo object to control a servo 
          
              
              
              
                
int servoPin1 = 5;
int servoPin2 = 6;
int servoPin3 = 9;
int servoPin4 = 10;
int servoPin5 = 11;

int flexPin1 = A0;
int flexPin2 = A1;
int flexPin3 = A2;
int flexPin4 = A3;
int flexPin5 = A4;



void setup() 
{ 
  Serial.begin(9600);
  myservo.attach(9);  // attaches servo on pin 9 to the servo object 
  
  myservo01.attach(10); //attaches sevo on pin 10 to the servo object
  
  myservo02.attach(6); //attaches sevo on pin 6 to the servo object
  
  myservo03.attach(11); //attaches sevo on pin 11 to the servo object
  
  myservo04.attach(3); //attaches sevo on pin 3 to the servo object
  
} 
 
 
void loop() 
{ 
  
    //This is the programming for #24 flex sensor
    int myservo1 = analogRead(A1) - 630;

    pos1 = map(myservo1, 0, 190, 0, 180);
    //delay(24);
  
    //Serial.println(pos1);
    myservo.write(pos1);              // tell servo to go to position in variable 'pos1' 
    //delay(25);                       // waits 15ms for the servo to reach the position 
    

   
   //////////////////////////////////////////////////////////////////////////////////////////
   
   
   
     
    //This is the programming for #38 flex sensor
    int myservo2 = analogRead(A2) - 450;

    pos2 = map(myservo2, 170, 400, 0, 180);
   // delay(24);
  
    //Serial.println(pos2);
    myservo01.write(pos2);              // tell servo to go to position in variable 'pos2' 
   // delay(25);                       // waits 15ms for the servo to reach the position 
    

   
   
   //////////////////////////////////////////////////////////////////////////////////////////
   
   
   
   
   
    //This is the programming for #34 flex sensor   
    int myservo3 = analogRead(A3) - 608;

    pos3 = map(myservo3, 0, 160, 0, 180);
    //delay(24);
  
    //Serial.println(pos3);
    myservo02.write(pos3);              // tell servo to go to position in variable 'pos3' 
    //delay(24);                       // waits 15ms for the servo to reach the position 
    
    
    
    
    
    //////////////////////////////////////////////////////////////////////////////////////////
       
   
   
   
   
    //This is the programming for #17 flex sensor   
    int myservo4 = analogRead(A0) - 550;

    pos4 = map(myservo4, 0, 100, 0, 180);
   // delay(24);
  
    //Serial.println(pos3);
    myservo03.write(pos4);              // tell servo to go to position in variable 'pos4' 
    //delay(24);                       // waits 15ms for the servo to reach the position 
    
    
    
    
    
    //////////////////////////////////////////////////////////////////////////////////////////
           
   

   
   
    //This is the programming for #30 flex sensor   
    int myservo5 = analogRead(A4) - 600;

    pos5 = map(myservo5, 0, 170, 0, 180);
   // delay(24);
  
    //Serial.println(pos3);
    myservo04.write(pos5);              // tell servo to go to position in variable 'pos5' 
   // delay(24);                       // waits 15ms for the servo to reach the position 
    
    
    

    
    //////////////////////////////////////////////////////////////////////////////////////////
    
    
    
   Serial.println(myservo1);
   Serial.print("      ");
   Serial.print(myservo2);
   Serial.print("      ");
   Serial.print(myservo3);
   Serial.print("      ");
   Serial.print(myservo4);
   Serial.print("      ");
   Serial.print(myservo5);
   Serial.print("      ");
     
   delay(200);   

   
    
}

Any help would be appreciated, thank you.

Print out the readings from your flex sensors, do they all change when all the servos change?

Hi, can you supply some specs please.
How many servos, specifications.
How many flex, specification.
Power supply, specification.

Can you please post a copy of your circuit, in CAD or picture of hand drawn circuit in jpg, png or pdf format.

Tom..... :slight_smile:

A DC power supply is connected to the Arduino to provide power to all servos (set on 6v)

It's not clear to me if you mean the servos are powerd through the Arduino or directly from that power supply.

JimboZA:

A DC power supply is connected to the Arduino to provide power to all servos (set on 6v)

It's not clear to me if you mean the servos are powerd through the Arduino or directly from that power supply.

The servos are directly powered through the DC power supply, while the flex sensors are powered through the Arduino.
Sorry about the confusion.

A DC power supply is connected to the Arduino to provide power to all servos (set on 6v),

Below is the way you should be externally powering the servos.

Grumpy_Mike:
Print out the readings from your flex sensors, do they all change when all the servos change?

They do not; the only value that changes completely is the sensor which is being flexed.
Every now and then there is also a sudden surge of power which decreases the values and the servos begin to rotate automatically. Not sure why.

Hi can you post a picture of your project and a CAD or picture of your circuit in jpg, png or pdf format please.

Tom.... :slight_smile:

Every now and then there is also a sudden surge of power which decreases the values and the servos begin to rotate automatically.

That does not sound like a surge but a dip.
Any decoupling on the servo's power supply?

TomGeorge:
Hi can you post a picture of your project and a CAD or picture of your circuit in jpg, png or pdf format please.

Tom… :slight_smile:

I do not have any CAD drawings, they will be completed in a few weeks (we were told to draw the circuit first).
Here is the veroboard which is connected to the arduino, the wired connection on the underside are for the A0-A4 pins for each flex sensor. The Servos are connected to the ‘~’ connections of the arduino (being connection ~3, ~5, ~6, ~9, ~10) .

Not a capacitor in sight!

Grumpy_Mike:
Not a capacitor in sight!

I had actually just placed a 470uf capacitor between the leading ground and 5v leads right after posting; thought it may be a good idea.
Still having jitter every so often, and the same problems are occurring. Sorry for not updating the progress.

Is it less often that without the capacitor?
Also try a 0.1uF ceramic in parallel.

deagle:
I do not have any CAD drawings,

Going by your profile name, you should have this already :stuck_out_tongue:

Grumpy_Mike:
Is it less often that without the capacitor?
Also try a 0.1uF ceramic in parallel.

Yes, there is less jitter now. I will try the 0.1uF tomorrow, I shall let you know then. Thank you.

A DC power supply is connected to the Arduino to provide power to all servos (set on 6v), and the voltage from the Arduino itself powers the flex sensors.

If 6v is being supplied to the external power plug on the arduino, what is the measured voltage on the arduino 5v pin? There may be a significant voltage drop across the onboard regulator. If your code/sensor setup is causing a lot of constant servo movement commands, then your power supply may be inadequate to supply the needed current for five servos constantly being commanded to move.