Control a Servo Motor with Arduino Uno Using Simple Code

Introduction

In this tutorial, we will learn how to control a servo motor with Arduino Uno. Servo motors are used in various applications like robotics, etc.

Components

components used in this project are,

  1. Arduino Uno
  2. Servo Motor
  3. Jumper Wire

Arduino Uno

Arduino Uno is a Microcontroller board that uses Atmega 328p. This development board has 14 digital I/O pins and 6 Analog pins, the arduino uno has beginner friendly and best for starters. which is mostly used by students, engineering students and hobbyists.

Servo Motor

A servo motor is a special type of motor that can be used for rotating with a specific angle and rotating with high accuracy. The servo motor is different from a normal electrical motor because a normal motor runs continuously, but a servo motor rotates with a specific angle, 0 °, 30 °, 45 °, 90 °, etc.

The servo motor has 3 pins, namely VCC, GND and Signal

VCC – this pin is used to supply 5V to the Servo motor
GND – this pin is connected to the ground (negative)
SIGNAL – this pin is used to provide the signal for the operation of the servo motor

Circuit Connection

The connection for this tutorial is very simple

Servo MotorArduino Uno
VCC5V
GNDGND
SIGNALD3
Servo Motor with Arduino Uno Schematic
Servo Motor with Arduino Uno Schematic

Step 1: Connect the circuit as per the Schematic and Circuit connection details

Step 2: Connect the Arduino Uno programming cable to the PC

Step 3: Open Arduino IDE and copy and paste the program given below

// Project  - Servo Motor Interfacing with Arduino Uno
// Programmed By :  KAVIKUMARAN
// Visit Our Website : Sololearners.com

#include <Servo.h>

Servo myServo;
const int servo1 = 3;


void setup() {
  myServo.attach(servo1); // Servo signal pin connected to pin 3
}

void loop() {
  myServo.write(0);    // Move to 0°
  delay(1000);

  myServo.write(90);   // Move to 90°
  delay(1000);

  myServo.write(180);  // Move to 180°
  delay(1000);
}
Servo Motor with Arduino Uno Wiring Diagram
Servo Motor with Arduino Uno Wiring Diagram

What is a servo motor?

A servo motor is a motor designed to rotate to a specific angle with precision. It is commonly used in robotics, automation, and control systems.

Does the servo motor need a PWM Pin?

PWM pin is not a compulsory need for the servo motor when we use the Servo.h header library

Leave a Comment

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

Scroll to Top