Pages: [1] 2   Go Down
Author Topic: Unable To Use Multiple Servos On Arduino  (Read 1413 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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. 
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34528
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Victoria, Australia
Offline Offline
Edison Member
*
Karma: 46
Posts: 1613
Electronics Engineer/Industrial Control
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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..... smiley
Logged

Everything runs on smoke, let the smoke out, it stops running......VK3DMK

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 105
Posts: 4679
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

The Elders of the Internet know who I am
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9682
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Victoria, Australia
Offline Offline
Edison Member
*
Karma: 46
Posts: 1613
Electronics Engineer/Industrial Control
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.... smiley
Logged

Everything runs on smoke, let the smoke out, it stops running......VK3DMK

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34528
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.... smiley

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) .


* image.jpeg (160 KB, 640x1136 - viewed 18 times.)

* image2.jpeg (200 KB, 640x1136 - viewed 10 times.)

* image 3.jpeg (224 KB, 640x1136 - viewed 9 times.)

* image 4.jpeg (248 KB, 640x1136 - viewed 13 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34528
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not a capacitor in sight!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34528
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 105
Posts: 4679
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I do not have any CAD drawings,

Going by your profile name, you should have this already  smiley-razz
Logged

The Elders of the Internet know who I am
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1] 2   Go Up
Jump to: