Pages: [1]   Go Down
Author Topic: Using Multiple Servos with Arduino  (Read 5902 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Johannesburg UTC+2
Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* servos_bb.jpg (1034.03 KB, 2850x1728 - viewed 1238 times.)
Logged

Have you looked for answers in the Learning, Reference, Products and Playground tabs on http://arduino.cc/en/ ?
Look here http://electronicsclub.info/ for basic electronics

0
Offline Offline
Tesla Member
***
Karma: 116
Posts: 8942
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Basic servo setup.

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: 1
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Zoomkat, makes perfect sense. Thank you as well.
Logged

Johannesburg UTC+2
Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Thanks Zimbo

That's Jimbo  smiley-cool, 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]
Logged

Have you looked for answers in the Learning, Reference, Products and Playground tabs on http://arduino.cc/en/ ?
Look here http://electronicsclub.info/ for basic electronics

yogyakarta
Offline Offline
Newbie
*
Karma: 0
Posts: 1
learning by expostulating
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Tesla Member
***
Karma: 116
Posts: 8942
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
//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
    }
  }
}

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: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: January 06, 2014, 03:45:55 am by jmichael26 » Logged

Johannesburg UTC+2
Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Have you looked for answers in the Learning, Reference, Products and Playground tabs on http://arduino.cc/en/ ?
Look here http://electronicsclub.info/ for basic electronics

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

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

Johannesburg UTC+2
Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Have you looked for answers in the Learning, Reference, Products and Playground tabs on http://arduino.cc/en/ ?
Look here http://electronicsclub.info/ for basic electronics

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

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
Logged

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

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
Logged

Pages: [1]   Go Up
Jump to: