Professional Documents
Culture Documents
Servo Motor Control Using Arduino (/microcontroller-Projects/arduino-Servo-Motor-Control-Code-And-Circuit)
Servo Motor Control Using Arduino (/microcontroller-Projects/arduino-Servo-Motor-Control-Code-And-Circuit)
ARDUINO (HTTPS://CIRCUITDIGEST.COM/ARDUINO-PROJECTS)
and accurate position application. These motors are used in robotic arm machines, flight AVHT Series High-
controls and control systems. Temperature Varistors
(https://bit.ly/3gFrqb5 )
AVHT high-temperature varistors
offer great circuit-board layout
(https://bit.ly/3gFrqb5
flexibility for designers
)
Model SF-0603HIA-M/SF-
1206HIA-M Series SMD Fuse
Families
(https://bit.ly/3jGGdCJ )
The Model SF-0603HIA-M/SF-
(https://bit.ly/3jGGdCJ
1206HIA-M series utilize Bourns'
) popular multilayer ceramic design
available at different shapes and sizes. A servo motor will have mainly there wires, one is
for positive voltage another is for ground and last one is for position setting. The RED wire
is connected to power, Black wire is connected to ground and YELLOW wire is connected (https://bit.ly/3jMmLEm
to signal. )
Chip LAN Transformer
Module - Model SM41126EL
Series
(https://bit.ly/3kJw7lG )
The SM41126EL Chip LAN
(https://bit.ly/3kJw7lG
10/100 Base-T transformer
) module is ideal for use in LAN
interfaces
Simply speaking the control electronics adjust shaft position by controlling DC motor.
This data regarding position of shaft is sent through the SIGNAL pin. The position data to
the control should be sent in the form of PWM signal through the Signal pin of servo
(https://bit.ly/2QkLGCH)
motor.
As shown in figure below, for the shaft to be moved to 9o clock the TURN ON RATION
Gas Sensors Market is
must be 1/18.ie. 1ms of ON time and 17ms of OFF time in a 18ms signal. projected to reach USD 2
Billion by 2026 (/news/gas-
(/news/gas- sensors-market-is-
sensors- projected-to-reach-usd-2-
market-is- billion-by-2026)
projected-to-
reach-usd-2-
billion-by-
2026)
Automotive
Microcontrollers from
STMicroelectronics to
(/news/automotive-
Maximize Safety and
microcontrollers-Security in Next-Generation
stmicroelectronics-
Domain/Zone Architectures
maximize- (/news/automotive-
safety-and- microcontrollers-
security-for- stmicroelectronics-
next- maximize-safety-and-
generation- security-for-next-
generation-domain-zone-
domain-zone-
architectures)
architectures)
(/fullimage?i=circuitdiagram_mic/servo-motor-control-using-arduino-uno.png)
In normal cases we need to go to the registers of controller for adjusting the frequency
and for getting required duty ratio for accurate position control of servo, in ARDUINO we
don’t have to do those things.
In ARDUINO we have predefined libraries, which will set the frequencies and duty ratios
accordingly once the header file is called or included. In ARDUINO we simply have to state
the position of servo that needed and the PWM is automatically be adjusted by UNO.
The things which we need to do for getting accurate position of servo are:
1. #include <Servo.h>
2. Servo sg90servo;
3. Sg90.attach(servo_signal_pin_attached_to);
4. Sg90.write(needed_position_ angle);
First we need to set frequency of PWM signal and for that we should call “#include
<Servo.h>” header file, on including this header file in the program, the frequency gets set
automatically and we get to use some special conditions, which enables the user to enter
needed position of servo directly without any fuzz.
•Now we need to define a name for the servo “Servo sg90sevo”, here ‘sg90servo’ is the
name chosen, so while writing for potion we are going to use this name, this feature
comes in handy when we have many servos to control, we can control as many as eight
servo by this.
Now we tell the UNO where the signal pin of servo is connected or where it needs to
generate the PWM signal. To do this we have “Sg90.attach(3);”, here we are telling the
UNO we connected the signal pin of servo at PIN3.
All left is to set the position, we are going set the position of servo by using
“Sg90.write(30);”, by this command the servo hand moves 30 degrees, so that’s it. After
that whenever we need to change the position of servo we need to call the command
”Sg90.write(needed_position_ angle);”. In this circuit we will have two buttons one button
increases the position of servo and the other is for decreasing the position of servo.
The Arduino Servo Motor control tutorial is explained in step by step of C code given
below.
Code
volatile int i=0;//initializing a integer for incrementing and decrementing duty ratio.
void setup()
void loop()
if (digitalRead(0)==LOW)
{
if (i<180)
{
}
}
if (digitalRead(1)==LOW)
{
if (i>0)
• {
delay(30);
}
}
}
Video
Email Address *
Name
Country
United States of America
Subscribe
RELATED CONTENT
(/microcontroller-projects/simple- (/microcontroller-projects/interfacing-
arduino-rc-boat-that-can-be-controlled- gravity-inrared-co2-sensor-to-measure-
wirelessly-using-rf-module) carbon-dioxide-in-ppm)
Build a Simple Arduino RC Boat that can Interfacing Gravity Infrared CO2 Sensor
be Controlled Wirelessly using 433 MHz with Arduino to Measure Carbon Dioxide
• RF Modules (/microcontroller- in PPM (/microcontroller-
projects/simple-arduino-rc-boat-that-can- projects/interfacing-gravity-inrared-co2-
be-controlled-wirelessly-using-rf-module) sensor-to-measure-carbon-dioxide-in-
ppm)
(/microcontroller-projects/arduino-based- (/microcontroller-projects/air-quality-
automatic-surface-disinfecting-robot- analyzer-using-arduino-and-nova-air-
using-ultraviolet-lights) quality-sensor-sds011)
Automatic Surface Disinfecting Robot Air Quality Analyzer using Arduino and
using Ultraviolet Lights (/microcontroller- Nova PM Sensor SDS011 to Measure
projects/arduino-based-automatic- PM2.5 and PM10 (/microcontroller-
surface-disinfecting-robot-using- projects/air-quality-analyzer-using-
ultraviolet-lights) arduino-and-nova-air-quality-sensor-
sds011)
(/microcontroller-projects/arduino-touch- (/microcontroller-projects/li-fi-
sensitive-color-changing-plants-using-rgb- communication-between-two-arduino)
leds) Li-Fi based Text Communication between
Touch Sensitive Color Changing Plants Two Arduino (/microcontroller-projects/li-
using Arduino and RGB LEDs fi-communication-between-two-arduino)
(/microcontroller-projects/arduino-touch-
sensitive-color-changing-plants-using-rgb-
leds)
(/microcontroller-projects/cell-phone-
controlled-fingerprint-solenoid-door-lock-
using-arduino)
Cell Phone Controlled Fingerprint
Solenoid Door Lock using Arduino and
HC-05 (/microcontroller-projects/cell-
phone-controlled-fingerprint-solenoid-
door-lock-using-arduino)
PREVIOUS POST
DTMF Controlled Robot using Arduino
(https://circuitdigest.com/microcontroller-
projects/dtmf-controlled-robot-using-
arduino)
(/microcontroller-projects/interfacing-
NEXT POST
sharp-gp2y1014au0f-sensor-with-arduino-
to-build-air-quality-analyzer)
• Interfacing Sharp GP2Y1014AU0F Sensor RFID Interfacing with Arduino
(https://circuitdigest.com/microcontroller-
with Arduino to build Air Quality Analyser
projects/rfid-with-arduino-uno-tutorial)
(/microcontroller-projects/interfacing-
sharp-gp2y1014au0f-sensor-with-arduino-
to-build-air-quality-analyzer)
COMMENTS
zeki
Jan 21, 2017
Naveed Aijaz
May 27, 2017
int buttonState = 0;
int buttonState2 = 0;
Servo servoA;
int position = 0;
int position1= 0;
void setup() {
servoA.attach(9);
pinMode(buttonPin, INPUT);
pinMode(buttonPin2,INPUT);
void loop() {
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
servoA.write(position++);
delay(1);
• }
servoA.write(position--);
delay(1);
servoA.write(position1++);
delay(1);
servoA.write(position1--);
delay(1);
(https://circuitdigest.com/power-
Subscribe
(https://www.facebook.com/circuitdigest/)
(https://twitter.com/CircuitDigest)
(https://www.youtube.com/channel/UCy3CUAIYgZdAOG9k3IPdLmw)
(https://www.instagram.com/circuit_digest/)
(https://www.pinterest.com/circuitdigest/)
electronics) ARDUINO PROJECTS
(/ARDUINO-PROJECTS)
Analog Electronics
(https://www.linkedin.com/company/circuit- RASPBERRY PI PROJECTS
(https://circuitdigest.com/analog-
(/SIMPLE-RASPBERRY-PI-
electronics) PROJECTS-FOR-BEGINNERS)
digest/)
Internet of Things
ELECTRONICS NEWS
(https://circuitdigest.com/internet-
(HTTPS://CIRCUITDIGEST.COM/NEWS)
of-things)
ELECTRONICS FORUM
Audio Electronics (HTTPS://CIRCUITDIGEST.COM/FORUMS)
(https://circuitdigest.com/audio-
electronics) CALCULATORS
(HTTPS://CIRCUITDIGEST.COM/CALCULATORS)
Electric Vehicles
(https://circuitdigest.com/electric-
vehicles)
•Events
(https://circuitdigest.com/events)
Copyright © 2020 Circuit Digest (http://circuitdigest.com/). All rights reserved. Privacy Policy (http://circuitdigest.com/privacy-policy) | Cookie Policy
(https://circuitdigest.com/cookie-policy) | Terms of Use
(https://circuitdigest.com/terms-of-use) | Contact Us
(http://circuitdigest.com/contact) | Advertise (http://circuitdigest.com/advertise)