Controlling 8 Servos with Arduino Uno

Hey all,

I was reading on the arduino page about being able to control up to 12 servos from an arduino uno. Although, the arduino uno has only 6 pwm pins; how is it possible to control more servos than the amount of provided pins? I was trying to find example codes on how this could be done or at least how a servo can be controlled without PWM. can someone please explain? i had some what of an idea i was wondering if someone can clarify. So i thought of connecting 2 servos in parallel since the move together with a different power line.

Servo 1 Servo 2
Pwr pin: Battery (+) Pwr pin: Battery (+)
Uno pin: ~10 Uno pin: ~10
GND Pin: Battery (-) GND Pin: Battery (-)

I wonder if there are any losses with this connection, if not i can connect all 8 servos with just 4 PWM pins.

I know servo drivers exist, but i am just curious to how the arduino can handle so many servos (12).

Thanks for yout input

A servo does not need a PWM pin.

...R

Robin2:
A servo does not need a PWM pin.

...R

can you provide example code ? i am curious now.

Try this on pin 8 (not PWM), type a number from 1 to 180 in the top of serial monitor and hit [ENTER].

include <Servo.h>
Servo servo;

void setup() {
  // initialize serial:
  Serial.begin(9600);
  servo.attach(8);
}
void loop() {
  // if there's any serial available, read it:
  while (Serial.available() > 0) {

    // look for the next valid integer in the incoming serial stream:
    int angle = Serial.parseInt(); 
    // look for the newline. That's the end of your
    // sentence:
    if (Serial.read() == '\n') {
    }
    angle = constrain(angle,0,180);
    servo.write(angle);
    Serial.print(angle);Serial.print("\t");
    Serial.println(servo.readMicroseconds());

  }
}

This is all documented in the Servo library - read the Servo.h (you should always read the .h file
of any library you use anyway, the information may be invaluable).

For example the Servo.h up-front explains it is interrupt-driven.

It also explains that various timers will become unavailable for PWM once you attach
servo(s).