CONTROL MANY SERVOS AT THE SAME TIME

Hi there, my name is Juan Carlos Ortiz Posada, from Medellín - Colombia. I am making many projects (Lightsabers, Robots, etc)

I have Arduino UNO and Arduino NANO, I am making a Robot Head and need to control 7 servos:

  • One servo to move eyes Up and Down.

  • One servo to move eyes Left and Right.

  • One servo to move the eyelid UP and Down (one for each eye).

  • One servo to Open and Close the Mouth.

  • One servo to move the neck Left and Right (to say no).

  • One servo to move the neck Up and Down (to say yes).

Thank you very much.

I've been trying to make it but I am new on this kind of stuff, son I need your help.

For the servos you will need a power supply capable of producing 5-6 V at several amperes, preferably more than 5 amperes. Do not attempt to power servos from the Arduino or small batteries.

There have been lots of threads recently discussing powering multiple servos. Here are links to a few of these threads.

http://forum.arduino.cc/index.php?topic=366517.0

http://forum.arduino.cc/index.php?topic=370762.0

https://forum.arduino.cc/index.php?topic=368417.0

Test code for controlling several servos.

//zoomkat 11-22-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added 
// Powering a servo from the arduino usually *DOES NOT WORK*.

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

Thank you very much, I will try all you say.

Obviously things move nice and slowly in Colombia.... :slight_smile:

zoomkat:

Jota-Bots: