What is a servo motor?
The servo motor is a special motor that you can rotate with a precision. It can be used to build remote control toys, etc. It is built in with several parts like a control circuit, servo motor, shaft, potentiometer, drive gears, an amplifier, and an encoder. The output shaft of this motor can be moved to any particular position, usually between 0 and 180 degrees. That is why this motor is best used in remote controlled toys.
In this blog, we will learn how to use the servo motor SG90. We will write a simple program to rotate the shaft of the servo motor from 0 to 90 degrees, and then to 180 degrees, and then back to 0 degrees. Once we understand the concept of the servo motor, we can use it for any application.
Components needed
- Servo motor SG90
- Power supply (optional for this servo motor)
- Jumper cables
- Arduino Uno board
- Breadboard
- A computer with the Arduino IDE installed
Completed Circuit

The program
// Include the Servo library
#include <Servo.h>
// Declare the Servo pin
int servoPin = 3;
// Create a servo object
Servo Servo1;
void setup() {
Servo1.attach(servoPin);
}
void loop(){
// Make servo go to 0 degrees
Servo1.write(0);
delay(1000);
// Make servo go to 90 degrees
Servo1.write(90);
delay(1000);
// Make servo go to 180 degrees
Servo1.write(180);
delay(1000);
// Make servo go to 90 degrees
Servo1.write(90);
delay(1000);
}