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