Arduino Projects

Arduino Servo motor control using Ultrasonic Sensor, Issues solved

Arduino Servo Motor Control:


Arduino Servo motor control- After reading this article, you will become experts in controlling servo motors. Because I am going to show you how to control small and large servo motors using

  • Arduino Uno.
  • Arduino Nano Development board with an external 5V power supply based on the 7805 voltage regulator. and
  • My newly designed Arduino Nano development board with a 5V and 3A power supply.

You can easily control small servos like the ones you can see in the image above using an Arduino Uno, but when it comes to larger servo motors, things start to get a bit complicated. I am using the word “complicated” specifically for beginners because they completely ignore the power supply while using Servo motors.

We will also check how many servo motors we can control at the same time if we only use Arduino without an external power supply.

Arduino Servo Motor Control

And we will see how many servos we can control if we use the 7805 voltage regulator with Arduino.

Arduino Servo Motor Control

Additionally, we will determine how many servo motors we can control if we use a 5V and 3A power supply.

5V, 3A Power Supply for Controlling Servo Motors with Arduino

For the demonstration purposes, I am going to use the HC-SR04 Ultrasonic Sensor to control low, medium, and high torque servo motors.

Arduino Servo Motor Control

So, without any further delay, let’s get started!!!

Amazon Links:

Arduino Nano USB-C Type (Recommended)

25Kg Torque Servo

10Kg Torque Servo

Small Servo

Other Tools and Components:

ESP32 WiFi + Bluetooth Module (Recommended)

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Different Types of Servos:

Micro Servo 9g (SG90):

Arduino Servo Motor Control

The SG90 (or 9G) servo motor is a popular choice for hobbyist projects due to its affordability, compact size, and relatively good performance for its price range. It is widely used in various applications such as remote-controlled vehicles, robotic arms, camera gimbals, and more.

The specifications of the SG90/9G servo motor typically include:

Torque: The torque rating for the SG90 servo motor is around 1.8 kg/cm (or 25 oz/in), which is suitable for small-scale projects.

Speed: The speed of the SG90 servo motor is approximately 0.1 seconds per 60 degrees of rotation.

Voltage and Current: The SG90 servo motor operates at a voltage range of 4.8V to 6V and consumes a current of around 200mA during movement.

Accuracy and Resolution: The SG90 servo motor provides reasonably good accuracy and resolution for most hobbyist applications, allowing for precise angular positioning.

Quality and Durability: The quality and durability of the SG90 servo motor can vary between different manufacturers. It’s advisable to choose reputable brands or check reviews to ensure reliability.

Price: The SG90 servo motor is typically an affordable option compared to more advanced servo motors.

MG996R Servo:

Arduino Servo Motor Control

The MG996R servo is a popular model of servo motor used in various robotic and electronics projects. Here’s some information about the MG996R servo:


The MG996R is a digital servo motor that operates on a 5V power supply. It has a stall torque of approximately 9.4 kg/cm (at 4.8V) or 11 kg/cm (at 6V), which means it can exert a maximum force of around 9.4 kg/cm or 11 kg/cm respectively when fully stalled. The servo has a rotation range of 180 degrees.

Control: The MG996R servo can be controlled using pulse width modulation (PWM) signals. It typically operates with a pulse width range of 500 to 2500 microseconds, where the center position is usually around 1500 microseconds. By varying the pulse width, you can control the servo’s position within its range.

Connector: The MG996R servo comes with a standard three-wire connector: red for power (+5V), brown or black for ground (GND), and orange or yellow for the control signal (PWM). The connector is commonly referred to as a “servo connector” or “JR connector.”

Dimensions: The MG996R servo has a standard size and shape. Its approximate dimensions are 40.7mm x 19.7mm x 42.9mm (L x W x H). It also has mounting holes that align with the standard servo mounting patterns.

Applications: The MG996R servo is widely used in robotics, RC (radio-controlled) vehicles, model airplanes, and other projects that require precise control of mechanical movement. It can be used for applications such as robotic arms, pan-tilt camera mounts, bipedal walking robots, and more.

SunFounder 25Kg High Torque Servo:

Arduino Servo Motor Control

The SunFounder DS-S020 Digital Servo is a specialized servo designed specifically for RC Robot Cars and Crawler Robots. It incorporates advanced potentiometer technology and employs stainless steel gears to ensure exceptional speed, strength, and accuracy in its performance. This servo motor stands out by delivering superior torque compared to other similar motors available from different sellers.


Large Torque: The servo motor offers a torque of 25kg/cm at 6.0V (≥22 kg·cm) and 7.4V (≥27 kg·cm), providing significant force for various applications.

High Rotation and Long Life: With a 180-degree rotation capability, the servo motor is well-controlled throughout the entire range. It boasts a long lifespan, capable of operating for over 200 hours.

High Precision: The servo motor utilizes advanced potentiometer technology and stainless steel gears to ensure high speed, strength, and accuracy in its movements.

Fast Heat Dissipation: Designed with a half aluminum alloy frame, the servo motor remains cool during operation, ensuring optimal performance and durability.

Widely Applicable: Suitable for high-speed vehicles, RC robots, and other automated equipment, this servo motor offers super high torque, precision, and low noise characteristics, making it a versatile choice.


Stall Torque: Ranging from 22kg/cm (305.5 oz/in) to 27kg/cm (374.9 oz/in)

No-load Speed: 0.20sec/60° to 0.24sec/60°

Operating Voltage: 6.0V to 7.4V DC

Pulse Width Range: 500μs to 2500μs

Weight: 73±0.5 g

Operating Travel Angle: 180° ±10° (500μs to 2500μs)

Max. Operating Travel Angle: 180° ±10° (500μs to 2500μs)

Motor Type: NdFeB motor

Gear Type: Metal

Reduction Ratio: 1/378

Left & Right Traveling Angle Deviation: ≤7°

Centering Deviation: ≤1°

Horn Gear Spline: 25T/Φ5.9mm

Size: 5.524.3cm

Stall Current: 6.0V, ≤4.5A (Continuous stall protection for 5 seconds)

Rotating Direction: Clockwise and forward (2500μs to 500μs)

Mechanical Limit Angle: 360°

Operating Temperature Range: -10℃ to +50℃

Storage Temperature Range: -20℃ to +60℃


Type: JR2.54/3Pin/Brown red-orange anti-reverse

Pin Assignment: Brown-GND, Red-Vcc, Orange-Signal/PWM

Mechanical Limit Angle: 360°

Servo Motor with Arduino Uno:

Circuit Diagram for Arduino Uno Servo Motor Control Using Ultrasonic Sensor

The VCC and GND pins of the Ultrasonic Sensor are connected to the Arduino Uno 5V and GND pins. Whereas the Trigger and Echo pins are connected to the Arduino Uno D9 and D8 pins respectively.

The Servo motor 5V and GND wires are connected to the Arduino Uno 5v and GND. While the Servo Motor Signal wire is connected to the Arduino Uno D3 pin, which is a PWM pin.

Small Servo Motor Arduino Programming:

As you can see, this is just a small program and its used to move the Servo Arm to 90 degrees when the distance is less than 30cm. I have already uploaded this program into the Arduino Uno. So, let’s go ahead and check all these Servos one by one.

Small Servo Motor with Arduino Uno Test:

I have powered up the Arduino board using my 4S lithium Ion battery.

Arduino Servo Motor Control Using Ultrasonic Sensor

This is also an external power supply but I use it to power up the entire board. I don’t use it to directly power up the servo motor but I use the onboard 5V regulated power supply. So, you can clearly see, I am using 5V from the Arduino.

Note: For the practical demonstration watch video tutorial given at the end of this article.

Anyway, in the image above you can see the Servo arm is at 0 position. When I placed my hand infront of the Ultrasonic Sensor the Servo arm moved to 900 . Now let’s connect the second servo motor and see if the Arduino’s onboard 5V voltage regulator can handle it. The code is unchanged; I am using the same pin D3 to control both the Servos.

Arduino Servo Motor Control

Arduino Uno can also handle two servo motors. The Servos arms moved to 90 degrees when I placed my hand in front of the Ultrasonic Sensor. Now, I am going to connect a 3rd servo.

Arduino Servo Motor Control

As you can see, Arduino Uno just can’t handle three servo motors at the same time. These three motors draw so much current that it causes the Arduino to restart. If you control one or two servos at the same time, you can still control multiple Servos. However, if you try to control these servos at the same time, they will behave abnormally.

Arduino Servo Motor Control

Next, I am going to check the MG996R Servo which is known for its high torque capabilities. It typically provides a torque of around 10Kg. Anyway, let’s go ahead and test it.

Arduino Servo Motor Control

I was able to control the MG996R Servo. Along with the MG996R Servo, I also connected a small servo motor.

A 10kg Torque Servo Connected to Arduino and Ultrasonic Sensor

The Arduino onboard 5V voltage regulator just can’t handle these two servo motors at the same time. But you can use a single MG996R Servo. Or you can control one servo at a time. But if you will try controlling both the servos at the same time then it won’t work.

Arduino Servo Motor Control

Now, I am going to test the SunFounder’s digital Servo. It provides a torque of 25Kg. Let’s go ahead and test it.

This servo has burnt the onboard voltage regulator and now the Arduino Uno is not turning on.

Arduino Servo Motor Control

So, do not power up any servos with a torque rating higher than 10kg using the onboard voltage regulator of Arduino Uno or Arduino Nano. Otherwise, your Arduino Uno will also get damaged. I already knew that this wouldn’t work because it struggled to handle a servo with 10kg torque.

Small Servo Motor with Arduino using 5V external power supply:

Arduino Servo Motor Control

Next, I am going to use this Arduino nano development board which has this 7805 voltage regulator and let’s see how many servos it can handle at the same time. Here is the circuit diagram,

Circuit Diagram for Arduino Servo Control Using 5V External Power Supply and Ultrasonic Sensor

As you can see I am using the same pin D3. And I am using the same code.

It handled one servo well and there were no issues. But when I connected two servos, they exhibited some abnormal behavior.

Arduino Servo Motor Control

You can see this jerkiness at the beginning ”watch video tutorial”. Anyway, if you’re building a robot or any project where you need to control two servos at the same time, I would say, just don’t use the 7805 voltage regulator.

And when I connected the MG996R Servo, it didn’t work at all.

Arduino Servo Motor Control

Adding a capacitor across the voltage and ground wires of the servo will definitely help. However, I still won’t recommend using the 7805 voltage regulator. As you connect different sensors, the 7805 voltage regulator will get hot and eventually burn out.

Small Servos with Arduino Nano and 5V 3A power supply Test:

Finally, I am going to use my newly designed Arduino Nano and LoRa-based development board. I have high expectations from this board because it has a 5V and 3A power supply.

5V, 3A Power Supply for Controlling Servo Motors with Arduino

I have specifically built this Arduino Nano development board for connecting and controlling multiple loads. Here is the simplified circuit diagram.

High-Ampere 5V Power Supply for High-Torque Servo Motors and Arduino

Simply connect the Vin of the 5V and 3A power supply to the Vin pin of the Arduino Nano and to the Servo Red wire. And don’t forget to connect all the grounds together.

Arduino Servo Motor Control

Anyway, I have slightly modified the code. Now, the servo motors will run continuously, and as you can see, all three servo motors are operating smoothly. I also test the MG996R Servo along with the small servo and it worked. I faced no issues due to the 3A power supply.

And now, finally, I am going to test this SunFounder’s 25kg torque servo. I have had this servo with me for quite some time, but I hadn’t tested it yet because my development board wasn’t ready back then. Anyway, let’s proceed and test this powerful servo.

A 25kg Torque Motor Connected to Arduino

Wow, this is simply amazing! The arm rotation is incredibly smooth and precise. I don’t see any jerky or abnormal behavior. The Arduino Nano is not restarting, which is a good sign. This servo has been running for about 4 minutes, and the power supply isn’t even warm. That’s very promising. How about if I connect the 10kg torque servo as well? Hmmm… Let’s do it.

Arduino Board with High-Torque Servo Motors

This is simply amazing; it can perfectly handle the two high torque servos. Still the movement is smooth, there is no jerkiness, and the Arduino Nano isn’t restarting. If it can control such high torque servos at the same time then I am sure it can also handle lots of small servos at the same time.

To perform your Arduino based experiments, you can make my designed Arduino Nano development board. I have already explained its designing and making. Or you can make my designed 5V and 3A power supply. I have used the same power supply on my development board. So, that’s all for now.

Watch Video Tutorial:


Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button