You are on page 1of 9

ARDUINO (HTTPS://CIRCUITDIGEST.COM/ARDUINO-PROJECTS)

Servo Motor Control using Arduino


(/microcontroller-projects/arduino-
servo-motor-control-code-and-circuit) CR01005 Series Thick-Film
Chip Resistor
By (page_author.html)Dilip Raja (/users/dilip-raja) Aug 15, 2015 2 (https://bit.ly/34JX0QT )
The CR01005 chip resistor
features a three-layer termination
(https://bit.ly/34JX0QT
process with a nickel barrier
)
SRP0310 /
SRP0315/SRP0410 /
SRP0510 / SRP0610 Series
Shielded Power Inductors
(https://bit.ly/31ZvmxA )
(https://bit.ly/31ZvmxA
SRP0310/0315/0410/0510/0610
) shielded power inductors have a
metal alloy powder core and flat wire

TBU-RS Dual Channel TBU®


High-Speed Protector Series
(https://bit.ly/3mIptNl )
The TBU-RS055-300-WH is an
integrated dual-channel TBU
(https://bit.ly/3mIptNl
overcurrent and TVS overvoltage
) protector

AEC-Q200 Compliant Thick


Servo Motor Interfacing with Arduino Uno Film Chip Resistors - Model
CRxxxxA Series
(https://bit.ly/34LdiZG )
In this tutorial we are going to control a servo motor by ARDUINO UNO. Servo Motors are The model CRxxxxA AEC-Q200
(https://bit.ly/34LdiZG
used where there is a need for accurate shaft movement or position. These are not compliant chip resistor series is
) available in eight different
proposed for high speed applications. These are proposed for low speed, medium torque footprints

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

SRP4018FA Series Power


Inductors
(https://bit.ly/3jMmLEm )
SRP4018FA shielded power
inductors are designed to meet
high current density requirements
•Servo motors (http://circuitdigest.com/electronic-circuits/servo-motor-tester-circuit) are

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

A servo motor is a combination of DC motor, position control system, gears. The position


of the shaft of the DC motor is adjusted by the control electronics in the servo, based on
the duty ratio of the PWM signal the SIGNAL pin.

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.

NEWS ARTICLES PROJECTS


Simplify cloud complexity
High Accuracy, 40 KHz Hall-
effect Current Sensor IC for
Think all-in-one. Think Dynatrace.
Starter Generators and
(/news/high- Traction Inverter Control
accuracy-40- (/news/high-accuracy-40-
khz-hall- khz-hall-effect-current-
effect-current- sensor-ic-for-starter-
Dynatrace Sign Up
sensor-ic-for- generators-and-traction-
starter- inverter-control)
The frequency of PWM (Pulse Width Modulated) signal can vary based on type of servo generators-
motor. The important thing here is the DUTY RATIO of the PWM signal. Based on this and-traction-
inverter-
DUTY RATION the control electronics adjust the shaft.
control)

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)

Low Cost Automotive


Sequential LED Lighting IC
for Reducing Design
(/news/low- Complexity and
cost- Development (/news/low-
automotive- cost-automotive-sequential-
sequential- led-lighting-ic-for-reducing-
led-lighting-ic- design-complexity-and-
for-reducing- development)
design-
complexity-
•For the shaft to be moved to 12o clock the ON time of signal must be 1.5ms and OFF time and-
development)
should be 16.5ms.  This ratio is decoded by control system in servo and it adjusts the
position based on it. This PWM in here is generated by using ARDUINO UNO. RTG4 Field Programmable
Gate Array (FPGA) in a
Circuit Components (/news/rtg4-
Ceramic Quad Flat Pack
(CQFP) for Simplified
field- System Designs in Satellite
Hardware: ARDUINO UNO, power supply (5v), 100uF capacitor , buttons (two pieces), 1KΩ programmable- and Space Probes
resistor (two pieces), Servo motor (which needed to be tested).    gate-array- Applications (/news/rtg4-
fpga-ceramic- field-programmable-gate-
Software: arduino IDE (Arduino nightly). quad-flat- array-fpga-ceramic-quad-
pack-cqfp-for- flat-pack-cqfp-for-
simplified-system-designs-
Arduino Servo Motor Circuit Diagram and Explanation simplified-
satellite-and-space-probes-
system-
applications)
designs-
satellite-and-
space-probes-
applications)

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.

#include <Servo.h>// header file for controlling servo

Servo servo;//defining the name usage as servo itself

void setup()

                pinMode(3, OUTPUT);   // sets the pin3 as output

                pinMode(0, INPUT);// sets the pin0 as output

                pinMode(1, INPUT);// sets the pin1 as output

void loop()

                servo.write(i);//set servo potion ‘i’ degrees

                if (digitalRead(0)==LOW)

                {

                                if (i<180)

                                {

                                                i++;//if pin0 is pressed and degrees is less than 180

                                                delay(30);

                                }

                }

                if (digitalRead(1)==LOW)

                {

                                if (i>0)


•                                { 

                                                i--;// if pin1 is pressed and degrees is greater than 0

                                                delay(30);

                                }

                }

}

 

Video

TAGS ARDUINO (/TAGS/ARDUINO) ARDUINO UNO (/TAGS/ARDUINO-UNO)

SERVO MOTOR (/TAGS/SERVO-MOTOR) EMBEDDED (/TAGS/EMBEDDED)

Get Our Weekly Newsletter!


Subscribe below to receive most popular news, articles and DIY projects from Circuit Digest

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

İt gives error, wil not work because you dont enter a


Log in (/user/login?destination=node/129%23comment-form) or register
(/user/register?destination=node/129%23comment-form) to post comments
servo.attach(servo data pin number); command... and also
pinMode(3, OUTPUT); // sets the pin3 as output

pinMode(0, INPUT);// sets the pin0 as output

pinMode(1, INPUT);// sets the pin1 as output

is false.. ınput command do not make output...


try better....

Naveed Aijaz
May 27, 2017

This is 100% working code,.


Log in (/user/login?destination=node/129%23comment-form) or register
(/user/register?destination=node/129%23comment-form) to post comments
When push button1 is pressed, it goes from 0 to 90 degrees.
When push button2 is pressed, it goes from 0 to 180 degrees
Regards,
Code:
#include <Servo.h>

const int buttonPin = 2;

const int buttonPin2 = 4;

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);

if(buttonState ==HIGH && position < 180){

servoA.write(position++);

delay(1);
• }

if(buttonState == LOW && position > 90){

servoA.write(position--);

delay(1);

if(buttonState2 ==HIGH && position1 < 180){

servoA.write(position1++);

delay(1);

if(buttonState2 == LOW && position1 > 3){

servoA.write(position1--);

delay(1);

LOG IN (/USER/LOGIN?DESTINATION=NODE/129%23COMMENT-FORM) OR REGISTER


(/USER/REGISTER?DESTINATION=NODE/129%23COMMENT-FORM) TO POST
COMMENT

Leo: Resolution up to 0.2mm


Resolution up to 0.2mm. Scan even more complex
objects with Leo than ever before.

Artec 3D Learn More

CATEGORIES POPULAR NEWSLETTER

Embedded ROBOTICS (/ROBOTICS- Sign Up for Latest News


Electronics PROJECTS)
Connect with us on social media and stay
(https://circuitdigest.com/embedded) Enter your email
updated with latest news, articles and projects!
555 CIRCUITS (/555-TIMER-
Power Electronics CIRCUITS)

(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)

You might also like