Home Industry InsightBLDC
Looking for a suitable motor? Looking for a suitable motor?
Looking for a suitable motor?

How to Connect Two Servo Motors to Arduino for Seamless Control

小编

Published2025-10-15

If you're looking to level up your Arduino projects, connecting multiple servo motors is a great way to introduce complex movements. In this guide, we'll walk you through how to connect two servo motors to an Arduino, offering easy-to-follow steps and tips to achieve smooth control for your robotics, automation, or mechanical projects.

Arduino, servo motors, servo control, Arduino project, motor control, robotics, electronics, Arduino tutorial, DIY robotics

Introduction to Servo Motors and Arduino

If you've ever worked with Arduino, you know it offers endless possibilities for DIY electronics projects. One of the most popular applications involves controlling servo motors, which allow you to add mechanical movement to your projects, from robotics to automated systems. Whether you are building a robot arm or a simple robotic car, connecting servo motors to Arduino is an essential skill for creating precise movement.

What Are Servo Motors?

Before diving into the wiring and coding, let’s quickly review what a servo motor is and how it works. Unlike regular DC motors, which rotate continuously, servo motors are designed to rotate within a limited range. A servo can turn to specific positions based on the input signal it receives, making it ideal for applications that require precise control.

Servo motors are equipped with a feedback mechanism, typically a potentiometer, that constantly monitors the position of the motor shaft. This feedback loop ensures the motor stops at the desired angle when given a control signal. Servo motors usually come in two varieties: standard and continuous rotation. For this guide, we will focus on standard servo motors, which are often used in robotic arms, RC vehicles, and even camera gimbals.

Why Use Arduino with Servo Motors?

Arduino boards are incredibly versatile and come with built-in libraries that simplify the process of controlling servo motors. The most commonly used library is the "Servo" library, which lets you easily control multiple servos with just a few lines of code. Arduino’s simplicity and accessibility make it the go-to platform for hobbyists and engineers who want to create automated systems without the complexity of professional controllers.

Connecting a single servo motor to Arduino is straightforward. However, controlling multiple motors at once can introduce new challenges, such as ensuring that the signals remain accurate and responsive. This is where understanding how to connect and control two servos with Arduino becomes crucial.

Components You’ll Need:

To connect two servo motors to Arduino, you will need the following components:

Arduino Board (Arduino Uno is a great choice)

Two Servo Motors (such as SG90 or MG90)

Jumper Wires

Breadboard (optional, for organized wiring)

External Power Supply (optional, for larger servos that draw more power)

Wiring the Servo Motors to Arduino

Step 1: Understanding the Pins on the Servo Motors

Servo motors have three wires:

Power (usually red): This is connected to a positive voltage source (5V in most cases).

Ground (usually black or brown): This is connected to the Arduino’s ground (GND).

Signal (usually yellow or white): This is the control wire, connected to one of the Arduino’s PWM-capable pins.

In this guide, we will assume you are using standard small servo motors, which typically operate at 5V and draw relatively little current. If you are using larger servos or high-power motors, you may need an external power supply.

Step 2: Connecting the Servos

First Servo:

Connect the red wire (power) from the first servo to the 5V pin on the Arduino.

Connect the black or brown wire (ground) to one of the GND pins on the Arduino.

Connect the yellow or white wire (signal) to Pin 9 on the Arduino.

Second Servo:

Connect the red wire (power) from the second servo to the 5V pin on the Arduino.

Connect the black or brown wire (ground) to one of the GND pins on the Arduino.

Connect the yellow or white wire (signal) to Pin 10 on the Arduino.

Step 3: External Power (Optional)

If your servo motors are high-torque or you're using several servos, the Arduino’s 5V pin may not supply enough current to power both motors effectively. In this case, consider using an external power supply to power the servos. If you do this, ensure that the ground of the external power supply is connected to the GND pin on the Arduino to create a common ground.

Writing the Code to Control Two Servo Motors

Now that your hardware is set up, it’s time to write the code that will control your two servo motors. Arduino’s Servo library makes this task easy, allowing you to control the position of each motor with just a few lines of code.

Step 1: Import the Servo Library

First, we need to include the Servo library in our Arduino sketch. This library provides all the functions necessary to control servo motors.

#include

Step 2: Define the Servo Objects

In your Arduino sketch, you need to create objects for each servo motor you’re using. We will define two servo objects: one for each motor.

Servo servo1;

Servo servo2;

Step 3: Set Up the Servo Motors in the setup() Function

In the setup() function, we’ll attach each servo to the appropriate pin on the Arduino. This tells the Arduino which pins the servos are connected to.

void setup() {

servo1.attach(9); // First servo is connected to pin 9

servo2.attach(10); // Second servo is connected to pin 10

}

Step 4: Control the Servo Motors in the loop() Function

Now, let’s define some positions for the servos to move to. Servo motors typically accept values from 0 to 180, representing the range of movement (from 0° to 180°). In the loop() function, you’ll move the motors to different angles in a loop, creating the effect of continuous movement.

void loop() {

// Move servo 1 from 0 to 180 degrees

for (int pos = 0; pos <= 180; pos++) {

servo1.write(pos); // Move the first servo to the position "pos"

delay(15); // Wait for the servo to reach the position

}

// Move servo 2 from 0 to 180 degrees

for (int pos = 0; pos <= 180; pos++) {

servo2.write(pos); // Move the second servo to the position "pos"

delay(15); // Wait for the servo to reach the position

}

// Move both servos back to 0 degrees

for (int pos = 180; pos >= 0; pos--) {

servo1.write(pos); // Move the first servo back to 0 degrees

servo2.write(pos); // Move the second servo back to 0 degrees

delay(15); // Wait for the servos to reach the position

}

}

Step 5: Upload and Test the Code

Once your code is ready, click the Upload button in the Arduino IDE. The servo motors should begin moving according to the instructions in your code. You can adjust the delay times or add more logic to make the motors perform specific tasks, such as opening a robotic gripper or controlling a camera pan/tilt system.

Tips for Better Servo Control

Power Supply: If you’re using multiple servos or large servos that require more power, always use an external power source to avoid overloading the Arduino’s power supply.

PWM Pins: Arduino boards like the Uno can handle up to 12 PWM signals, meaning you can control up to 12 servo motors simultaneously. Make sure to use PWM-capable pins for the signal wires (Pins 3, 5, 6, 9, 10, and 11 on the Arduino Uno).

Servo Load: If you attach a heavy load to your servo motors, they might struggle to reach the desired position. Ensure the servos are not overloaded beyond their rated torque.

Conclusion

Connecting two servo motors to an Arduino is a straightforward task, but mastering it opens up a world of possibilities for your DIY electronics projects. By following this guide, you can successfully control two servos, creating the foundation for more advanced robotic systems, automated machines, and interactive installations.

Established in 2005, Kpower has been dedicated to a professional compact motion unit manufacturer, headquartered in Dongguan, Guangdong Province, China.

Update:2025-10-15

Contact a motor expert for product recommendation.
Contact a motor expert for product recommendation.

Powering The Future

Contact Kpower's product specialist to recommend suitable motor or gearbox for your product.