This experiment demonstrates how to control 6 servos simultaneously, which is the maximum number of servos that can be controlled by an Arduino Uno without using additional servo driver boards.
It is important to note that the pins on the Arduino Uno that can connect to servos need to be PWM-enabled, which are the pins marked with a ~ (tilde) on the board.
Servos consume a lot of power; the Arduino Uno can drive 2-3 9g servos without issues, but to ensure stable operation of all servos, an external power supply is necessary. In this experiment, we use 5V servos, which can be directly connected to the DC power port on the Arduino Uno.
However, when connecting other power sources, it is crucial to understand the positive and negative connections. This should be done under the guidance of an experienced person; never take chances when unsure, as this could lead to unpredictable electrical hazards.
Experiment Results
During the experiment, the servos perform the following actions: 1. All servos rotate from 0 degrees to 179 degrees simultaneously; 2. All servos rotate from 180 degrees to 1 degree simultaneously; 3. All servos quickly rotate to 90 degrees simultaneously; 4. All servos quickly rotate to 180 degrees simultaneously; 5. All servos quickly rotate back to 90 degrees simultaneously; 6. 3 servos rotate to 0 degrees while the other 3 servos rotate to 180 degrees; 7. 3 servos rotate from 0 degrees to 179 degrees while the other 3 servos rotate from 180 degrees to 1 degree; 8. 3 servos rotate from 180 degrees to 1 degree while the other 3 servos rotate from 0 degrees to 179 degrees.
For more details, please watch the video:
Component Description
The servos (basic) are driven by Arduino Uno.
If you have not used the above components separately, it is recommended to implement each one individually first.
BOM List
Name | Quantity |
---|---|
Arduino Uno | x1 |
Servos | x6 |
5V 2A Power Supply | x1 |
Breadboard | x1 |
Jumper Wires (Dupont Wires) | Several |
Wiring Method
Arduino Uno Pin | <—> | Servo Pin_1 |
---|---|---|
5V | <-> | VCC (Red) |
GND | <-> | GND (Black or Brown) |
3 | <-> | Signal Line (Orange) |
Arduino Uno Pin | <—> | Servo Pin_2 |
---|---|---|
5V | <-> | VCC (Red) |
GND | <-> | GND (Black or Brown) |
5 | <-> | Signal Line (Orange) |
Arduino Uno Pin | <—> | Servo Pin_3 |
---|---|---|
5V | <-> | VCC (Red) |
GND | <-> | GND (Black or Brown) |
6 | <—> | Signal Line (Orange) |
Arduino Uno Pin | <—> | Servo Pin_4 |
---|---|---|
5V | <-> | VCC (Red) |
GND | <-> | GND (Black or Brown) |
9 | <-> | Signal Line (Orange) |
Arduino Uno Pin | <—> | Servo Pin_5 |
---|---|---|
5V | <-> | VCC (Red) |
GND | <-> | GND (Black or Brown) |
10 | <-> | Signal Line (Orange) |
Arduino Uno Pin | <—> | Servo Pin_6 |
---|---|---|
5V | <-> | VCC (Red) |
GND | <-> | GND (Black or Brown) |
11 | <-> | Signal Line (Orange) |
The wiring is shown in the following image:
Program Highlights
The program is generally similar to the previous basic servo experiments, but it uses more for() loop statements. The for loop allows you to write a control structure that executes a specified number of times.
However, moving the servos to their target positions takes time, so for large movements, it is necessary to use delay() to wait.
Program Implementation
Clickto read the original text for a better code browsing experience
// lingshunlab.com
// Load Servo library
#include <Servo.h>
Servo servo_1; // Create a servo instance named servo_1 (name can be whatever you like)
Servo servo_2;
Servo servo_3;
Servo servo_4;
Servo servo_5;
Servo servo_6;
void setup() {
servo_1.attach(3); // Set the pin for myservo instance to 3
servo_2.attach(5);
servo_3.attach(6);
servo_4.attach(9);
servo_5.attach(10);
servo_6.attach(11);
}
void loop() {
// Control all servos to rotate from 0 degrees to 179 degrees
for(int i = 0; i < 180; i++) {
servo_1.write(i);
servo_2.write(i);
servo_3.write(i);
servo_4.write(i);
servo_5.write(i);
servo_6.write(i);
delay(10);
}
delay(500);
// Control all servos to rotate from 180 degrees to 1 degree
for(int i = 180; i > 0; i--) {
servo_1.write(i);
servo_2.write(i);
servo_3.write(i);
servo_4.write(i);
servo_5.write(i);
servo_6.write(i);
delay(10);
}
delay(500);
// Control all servos to rotate to the 90 degrees position
servo_1.write(90);
servo_2.write(90);
servo_3.write(90);
servo_4.write(90);
servo_5.write(90);
servo_6.write(90);
delay(500);
// Control all servos to rotate to the 180 degrees position
servo_1.write(180);
servo_2.write(180);
servo_3.write(180);
servo_4.write(180);
servo_5.write(180);
servo_6.write(180);
delay(500);
// Control all servos to rotate to the 90 degrees position
servo_1.write(90);
servo_2.write(90);
servo_3.write(90);
servo_4.write(90);
servo_5.write(90);
servo_6.write(90);
delay(500);
// Control some servos to rotate to 0 degrees or 180 degrees position
servo_1.write(0);
servo_2.write(180);
servo_3.write(0);
servo_4.write(180);
servo_5.write(0);
servo_6.write(180);
delay(500);
// Simultaneously control servos at 0 degrees to rotate to 179 degrees
// Simultaneously control servos at 180 degrees to rotate to 1 degree
for(int i = 0; i < 180; i++){
servo_1.write(0+i);
servo_2.write(180-i);
servo_3.write(0+i);
servo_4.write(180-i);
servo_5.write(0+i);
servo_6.write(180-i);
delay(10);
}
delay(500);
// Simultaneously control servos at 180 degrees to rotate to 1 degree
// Simultaneously control servos at 0 degrees to rotate to 179 degrees
for(int i = 0; i < 180; i++){
servo_1.write(180-i);
servo_2.write(0+i);
servo_3.write(180-i);
servo_4.write(0+i);
servo_5.write(180-i);
servo_6.write(0+i);
delay(10);
}
delay(500);
}
Leave a Comment
Your email address will not be published. Required fields are marked *