Introduction
In this tutorial, you will learn how to control a servo motor using an Arduino board. A servo motor is a type of motor that can rotate to a specific angle, making it ideal for precise motion control applications. By the end of this tutorial, you will be able to control a servo motor with your Arduino and create your own custom motion control systems.

Step 1:
Gather Materials
- Arduino board (e.g. Arduino Uno)
- Servo motor
- Breadboard
- Jumper wires
Step 2:
Connect Components Connect the servo motor to the breadboard and the Arduino board as follows:
- Connect the servo’s GND pin to the breadboard’s GND rail
- Connect the servo’s VCC pin to the breadboard’s +5V rail
- Connect the servo’s signal pin to Arduino pin 9
Step 3:
Write the Code Open the Arduino IDE and write the following code:
#include <Servo.h> Servo myservo; void setup() { myservo.attach(9); } void loop() { myservo.write(90); delay(1000); myservo.write(180); delay(1000); }
This code initializes the servo motor and attaches it to pin 9 on the Arduino board. It then sets the motor angle to 90 degrees and waits for one second, before setting the angle to 180 degrees and waiting for another second. You can modify the code to set the angle to any value between 0 and 180 degrees.
Advertisement
Step 4:
Upload the Code Connect the Arduino board to your computer using a USB cable and upload the code to the board.
Step 5:
Test the Motor With the code uploaded, the servo motor should begin moving between 90 and 180 degrees, pausing for one second at each position.
Conclusion
Advertisement