Multiple Servo Control with Arduino Uno

In this tutorial, you’ll learn how to control multiple servo motors simultaneously using an Arduino Uno R3. This setup is ideal for building projects such as robotic arms, animatronic systems, or mechanical controllers.

We’ll use four servo motors connected to Arduino PWM pins and control their motion through a simple sweep program.

Components Required

  • Arduino Uno R3
  • 4 × SG90 Micro Servo Motors
  • Breadboard
  • Jumper wires (male-to-male)
  • 9V Battery (or external 5–6V power supply for servos)

Understanding Servo Motors

Servo motors (like the SG90) are controlled by PWM (Pulse Width Modulation) signals. The servo rotates between 0° to 180°, depending on the width of the signal pulse.

  • Orange wire → Signal (PWM input)
  • Red wire → +5V (Power)
  • Brown wire → GND

Each servo draws a significant amount of current (around 500 mA at stall), so it’s important to use an external power supply instead of powering all servos directly from the Arduino.

Circuit Connections

Power and Ground Setup

  • Connect the battery (+) to the breadboard VCC line.
  • Connect the battery (–) to the breadboard GND line.
  • Connect Arduino GND to the breadboard GND line (common ground).

Servo Motor Connections

ServoSignal PinPowerGround
Servo1Digital PWM 3Breadboard VCCBreadboard GND
Servo2Digital PWM 5Breadboard VCCBreadboard GND
Servo3Digital PWM 6Breadboard VCCBreadboard GND
Servo4Digital PWM 9Breadboard VCCBreadboard GND

This setup ensures all servos share the same power source and control reference.

⚠️ Important Power Note

If you use multiple servos, do not power them from the Arduino’s 5V pin. Instead, use an external 5V–6V regulated power supply (e.g., 4xAA batteries or a DC adapter).
Always connect all grounds together (Arduino GND ↔ Servo GND ↔ Battery GND).

Arduino Code

#include <Servo.h>

// Create servo objects
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

// Servo position in degrees
int servoPos = 0;

void setup() {
  // Define servo signal pins (PWM 3, 5, 6, 9)
  servo1.attach(3);
  servo2.attach(5);
  servo3.attach(6);
  servo4.attach(9);
}

void loop() {
  // Sweep from 0° to 180°
  for (servoPos = 0; servoPos <= 180; servoPos++) {
    servo1.write(servoPos);
    servo2.write(servoPos);
    servo3.write(servoPos);
    servo4.write(servoPos);
    delay(20); // Small delay for smooth motion
  }

  // Sweep back from 180° to 0°
  for (servoPos = 180; servoPos >= 0; servoPos--) {
    servo1.write(servoPos);
    servo2.write(servoPos);
    servo3.write(servoPos);
    servo4.write(servoPos);
    delay(20);
  }
}

Code Explanation

  1. Servo Library:
    The Servo.h library handles PWM signal generation for controlling servo position.
  2. Servo Object Creation:
    Each servo motor gets its own instance (servo1, servo2, servo3, servo4).
  3. Sweep Logic:
    Two for loops move the servos gradually between 0° and 180°, then back to .
    The delay(20) provides smooth, synchronized movement.
  4. Synchronization:
    All servos move together because each loop iteration writes the same position to every servo.

Testing the Project

  1. Upload the code to your Arduino Uno.
  2. Power the system with an external 5–6V battery.
  3. Observe all four servo motors sweeping together from 0° to 180° and back.
  4. Adjust delay(20) for faster or slower motion.

Pro Tips

  • If servos jitter, check your power source — low current can cause instability.
  • You can control servos independently by assigning different motion sequences.
  • Try using potentiometers to control individual servo angles in real time. (Next tutorial!)
  • For more than 8 servos, consider a PCA9685 16-channel servo driver.

Conclusion

You’ve learned how to control multiple servo motors using an Arduino Uno R3.
This simple setup forms the basis for robotic arm control, biped movement, or interactive kinetic art projects.

In the next tutorial, we’ll build on this concept — using potentiometers to control multiple servos for precise manual control.

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir