Documentation

Basic 180° Servo Motor Control

Updated August 4, 2026

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

  1. Connect VCC of Servo Motor to 5V on the board.

  2. Connect GND of Servo Motor to GND on the board.

  3. Connect Signal pin to GPIO 9.

  4. 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

  1. Connect the board to your computer using USB.

  2. Open the code in Arduino IDE.

  3. Select the correct board.

  4. Select the correct port.

  5. Click Upload.

  6. 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 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.

Technical Article
By ZiraaSTEM