How to control a Servo using Arduino

In this one, servo is programmed to be controlled by two buttons, one turns servo to the left and the other one turns it to the right. When the servo is turning, corresponding LED will be switched on to indicate the operation.

Result:

Because Arduino has built-in library for controlling servo, which makes servo a really easy kit to use. In this project, I will be using a servo to turn the IR sensor around constantly.
This is the circuit Diagram:
This is the code:
// Oscar’s Project
//
// There are 2 input buttons (turn left and right), when button is pressed, the servo turns and corresponding LED is lit up.

#include

Servo myservo;  // create servo object to control a servo
// a maximum of eight servo objects can be created

Arduino control a Servo Schematic

int pos = 90;    // variable to store the servo position
const int maxDeg = 160;
const int minDeg = 5;

const int leftPin = 3;
const int rightPin = 2;

const int led1Pin = 6; // indicator
const int led2Pin = 5; // indicator

const int outputPin = 9; // pwm function will be disabled on pin 9 and 10 if using servo

int leftPressed = 0;

[box color=”#985D00″ bg=”#FFF8CB” font=”verdana” fontsize=”14 ” radius=”20 ” border=”#985D12″ float=”right” head=”Major Components in Project” headbg=”#FFEB70″ headcolor=”#985D00″]Arduino[/box]

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

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

Scroll to Top