Go Down

Topic: Using Multiple Servos with Arduino (Read 10567 times) previous topic - next topic

Sluice

So, I have 8 servos that I want to drive with my Arduino. I know I shouldn't connect all the servos to the GND and +5v of Arduino. Somebody told me that servos when working pull about 2 amps each Is this correct? How should I hook an external battery with Arduino to my servos? I am told that I can hook up DC jack into Arduino, an external batteries GND to Arduino's GND, and the external batteries + to +5v on Arduino. Is this correct? Please help me out here.

JimboZA

Yep that's right. Have a look at my pic below, and go and read DuaneB's work, starting here. He has some test results for current draw.
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

zoomkat

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Sluice

Thanks Zimbo for the tremendous help. I'm enjoying the website you linked to your post, it's very helpful. What I'm making is a 4 legged spider! (I really hope it works :)
Zoomkat, makes perfect sense. Thank you as well.

JimboZA

Quote
Thanks Zimbo


That's Jimbo  8), but you're welcome all the same.

Yep DuaneB seems to be the go-to-guy for servo know-how.

[zen]Is a 4-legged spider really a spider?[/zen]
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

aziz_wicaksono

oh it's so help me actually. Now, I use 5 servos in my project. Can anybody help me for give a little sketch ?  I am so confuse to start it.  :smiley-roll-sweat:

zoomkat


oh it's so help me actually. Now, I use 5 servos in my project. Can anybody help me for give a little sketch ?  I am so confuse to start it.  :smiley-roll-sweat:


Several servo control code.

Code: [Select]

//zoomkat 11-22-12 simple delimited ',' string parse
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added

String readString;
#include <Servo.h>
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
        }
         readString=""; //clears variable for new input
      }
    } 
    else {     
      readString += c; //makes the string readString
    }
  }
}

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

jmichael26

#7
Jan 06, 2014, 09:33 am Last Edit: Jan 06, 2014, 09:45 am by jmichael26 Reason: 1
hi! how to program it if i'll be needing more than 2 servo motors? thanks

i'll be making snake robot and there is 14 servo motors included.


just like this http://www.youtube.com/watch?v=YKlCzcH8oWk&feature=c4-overview&list=UUWVNKVqwlDwOcAsUMM4TJnA

JimboZA


hi! how to program it if i'll be needing more than 2 servo motors? thanks


Zoomcat's code in reply #6 shows 4 servos already, on pins 6, 7, 8 and 9.
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

jmichael26

ahh but what if i'll be using 14 servos ?

JimboZA

Well you'll need an Arduino with 14 spare digital pins. Uno has 20 pins if you count the analogs, but lose 2 for Tx Rx leaves you a theoretical 18. Mega has dozens more .

I'm not sure if there's an absolute maximum that the servo library can handle though, sorry.
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

jmichael26

my friend told me that i need to use sevo drivers to accomodate those servos. but i'm just worried about its program . please help me

jmichael26


Well you'll need an Arduino with 14 spare digital pins. Uno has 20 pins if you count the analogs, but lose 2 for Tx Rx leaves you a theoretical 18. Mega has dozens more .

I'm not sure if there's an absolute maximum that the servo library can handle though, sorry.


but how is the program if i'll be using 14 servos? just copy paste your #6 program? thanks

Go Up