Basic 180° Servo Motor Control

1. What You Will Build
In this tutorial, you will learn how to build Basic 180° Servo Motor Control using Arduino.
By the end of this tutorial, your project will be able to:
Rotate the servo motor from 0° to 180°.
Move the servo motor between 180°, 90°, and 0° positions.
Repeat the programmed movement sequence continuously.
2. What You Will Learn
After completing this tutorial, you should understand:
How to connect a 180° servo motor to an Arduino Uno.
How to control the rotation direction and stop the servo motor.
How the Servo library works.
How the code works step by step
3. Components Needed
No. | Component | Quantity |
1 | Arduino | 1 |
2 | Servo motor(MG996R/SG90) | 1 |
3 | Jumper wires | several |
4 | USB cable | 1 |
4. Software Needed
Use the tools below depending on your board.
Board | Software |
Arduino | Arduino IDE |
Libraries Needed
Install these libraries before uploading/running the code:
Servo
5. Circuit Connection
Connect the components as shown below.
Component Pin | Connect To |
VCC | 5V |
GND | GND |
Signal | GPIO 9 |
Wiring Steps
Connect VCC of Servo Motor to 5V on the board.
Connect GND of Servo Motor to GND on the board.
Connect Signal pin to GPIO 9.
Double-check all wiring before powering the board.
Circuit Diagram

6. Code
#include <Servo.h>
Servo myServo;
void setup() {
myServo.attach(9);
}
void loop() {
myServo.write(180);
delay(3000);
myServo.write(90);
delay(2000);
myServo.write(0);
delay(3000);
myServo.write(90);
delay(2000);
}7. Upload / Run the Project
Connect the board to your computer using USB.
Open the code in Arduino IDE.
Select the correct board.
Select the correct port.
Click Upload.
Open the Serial Monitor if needed.
8. Expected Result
When the project is working correctly:
The servo rotates to 180° and stops for 3 seconds.
The servo moves to 90° and stops for 2 seconds.
The servo rotates to 0° and stops for 3 seconds.
The servo moves back to 90° and stops for 2 seconds.
The entire movement sequence repeats continuously until the power is turned off.
9. Troubleshooting
Problem | Possible Fix |
Board not detected | Check USB cable, driver, board, and port selection |
Code upload failed | Select the correct board and COM port |
Servo does not rotate | Check the GND,VCC and the signal wire connection |
Servo jitters | Use a stable 5V power supply and ensure all connections are secure. |