Вы находитесь на странице: 1из 11

7/15/2015 Interfacing Servo Motor with Atmega32 Atmel AVR Microcontroller

 (https://electrosome.com/cart/)

(https://electrosome.com)

Interfacing Servo Motor with Atmega32 Microcontroller
B Y   L I G O   G E O RG E   (HTTP S : / / E L E CTRO S O ME . CO M/ A UTHO R/ L I JO P P A NS / )  /   1   CO MME NT
(HTTP S : / / E L E CTRO S O ME . CO M/ I NTE RFA CI NG ­S E RV O ­MO TO R­WI TH­A TME G A 3 2 ­
MI CRO CO NTRO L L E R/ # CO MME NTS )

Servo Motor is a DC Motor equipped with error
sensing negative feedback to control the exact
angular position of the shaft. Unlike DC Motors
it will not rotate continuously. It is used to make
angular  rotations  such  as  0­90°,  0­180°  etc.
Stepper  Motors
(https://electrosome.com/stepper­motor/)  can
also  be  used  for  making  precise  angular
rotations.  But  Servo  Motors  are  preferred  in
angular  motion  applications  like  robotic  arm,
since  controlling  of  servo  motors  are  simple,
(https://electrosome.com/wp­
needs  no  extra  drivers  like  stepper  motor content/uploads/2012/06/Servo­Motor.gif)
(https://electrosome.com/stepper­motor/)  and
Servo Motor (https://electrosome.com/servo­motor/)
only angular motion is possible.

Operation of Hobby Servo Motor is very simple, it has only three wires, two of them (Red and
Black)  used  to  provide  power  and  the  third  wire  is  used  to  provide  control  signals.  Pulse
Width  Modulated  (https://electrosome.com/pwm­pulse­width­modulation/)  (PWM
(https://electrosome.com/pwm­pulse­width­modulation/))  waves  are  used  as  control  signals
and the angular position is determined by the width of the pulse at the control input. In this
tutorial we are using a servo motor having angle of rotation from 0­180° and angular position
can be controlled by varying the pulse width between 1ms to 2ms.

Note  :  Please  refer  the  datasheet  of  your  Servo  Motor,  before  using  the  program  in  this
tutorial. Angular range and control pulse width are different for different servo motors.

Product Support ­ Online
https://electrosome.com/interfacing­servo­motor­with­atmega32­microcontroller/ 1/11
7/15/2015 Interfacing Servo Motor with Atmega32 Atmel AVR Microcontroller

(https://electrosome.com/wp­content/uploads/2012/06/Servo­Angular­Rotation­
Pulse­Width­Modulation.jpg)
Controlling Angular Position of Servo Motor using Pulse Width Modulation (https://electrosome.com/pwm­
pulse­width­modulation/)

Circuit Diagram

https://electrosome.com/interfacing­servo­motor­with­atmega32­microcontroller/ 2/11
7/15/2015 Interfacing Servo Motor with Atmega32 Atmel AVR Microcontroller

(https://electrosome.com/wp­content/uploads/2013/05/Interfacing­Servo­Motor­with­
Atmega32­Microcontroller­Circuit­Diagram.jpg)
Interfacing Servo Motor with Atmega32 Microcontroller – Circuit Diagram

8 MHz Crystal is used to provide the required clock for Atmega32 Microcontroller and 22pF
capacitors are used to stabilize the operation of the crystal. 10KΩ resistor and 10μF capacitor
is used to provide the required Power On Reset (POR) to the microcontroller. Control of servo
motor is connected to the first pin of PORTC (RC0), which is declared as an output pin in the
program.

Atmel Studio C Program

https://electrosome.com/interfacing­servo­motor­with­atmega32­microcontroller/ 3/11
7/15/2015 Interfacing Servo Motor with Atmega32 Atmel AVR Microcontroller

#ifndef F_CPU
#define F_CPU 8000000UL // 8 MHz clock speed
#endif

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
  DDRC = 0x01; //Makes RC0 output pin
  PORTC = 0x00;
  while(1)
  {
    //Rotate Motor to 0 degree
    PORTC = 0x01;
    _delay_us(1000);
    PORTC = 0x00;

    _delay_ms(2000);

    //Rotate Motor to 90 degree
    PORTC = 0x01;
    _delay_us(1500);
    PORTC = 0x00;

    _delay_ms(2000);

    //Rotate Motor to 180 degree
    PORTC = 0x01;
    _delay_us(2000);
    PORTC = 0x00;

    _delay_ms(2000);
  }
}

You can download Atmel Studio files and Proteus files here…

Interfacing  Servo  Motor  with  Atmega32  Microcontroller  (https://electrosome.com/wp­


content/uploads/2013/05/Interfacing­Servo­Motor­with­Atmega32­Microcontroller.zip)

Related Posts:

https://electrosome.com/interfacing­servo­motor­with­atmega32­microcontroller/ 4/11
7/15/2015 Interfacing Servo Motor with Atmega32 Atmel AVR Microcontroller

Interfacing Servo Interfacing Servo Interfacing Servo


Motor with 8051 Motor with PIC Motor with PIC
using Keil C Microcontroller –… Microcontroller
(https://electrosome.com/interfacing­
(https://electrosome.com/servo­
(https://electrosome.com/servo­
servo­motor­with­ motor­pic­mplab­ motor­pic­
8051­using­keil­c/) xc8/) microcontroller/)

Interfacing Stepper
Motor with 8051
using Keil C –… Generating PWM
Servo Motor (https://electrosome.com/interfacing­
Using 555 Timer IC
(https://electrosome.com/servo­
stepper­motor­8051­ (https://electrosome.com/pwm­
motor/) keil­c­at89c51/) using­555­timer­ic/)

Interfacing DC Motor
with Atmega32
Microcontroller Stepper Motor or
(https://electrosome.com/interfacing­
Step Motor
dc­motor­atmega32­ (https://electrosome.com/stepper­
l293d/) motor/)

Like 3,460 people like this.

electroSome

Follow +1

+ 589

CATE G O RI E S :  A TME L   A V R  (HTTP S : / / E L E CTRO S O ME . CO M/ CA TE G O RY / TUTO RI A L S / A TME L ­A V R/ ),   TUTO RI A L S


 LOVE IT , SHARE IT
(HTTP S : / / E L E CTRO S O ME . CO M/ CA TE G O RY / TUTO RI A L S / )
TAG S :  A TME G A 3 2   (HTTP S : / / E L E CTRO S O ME . CO M/ TA G / A TME G A 3 2 / ),   A TME L
(HTTP S : / / E L E CTRO S O ME . CO M/ TA G / A TME L / ),   MI CRO CO NTRO L L E R

https://electrosome.com/interfacing­servo­motor­with­atmega32­microcontroller/ 5/11
7/15/2015 Interfacing Servo Motor with Atmega32 Atmel AVR Microcontroller

(HTTP S : / / E L E CTRO S O ME . CO M/ TA G / MI CRO CO NTRO L L E R/ ),   MO TO R  (HTTP S : / / E L E CTRO S O ME . CO M/ TA G / MO TO R/ ),


P RO TE US   (HTTP S : / / E L E CTRO S O ME . CO M/ TA G / P RO TE US / ),   S E RV O   (HTTP S : / / E L E CTRO S O ME . CO M/ TA G / S E RV O / ),
TUTO RI A L S   (HTTP S : / / E L E CTRO S O ME . CO M/ TA G / TUTO RI A L S / )

0 Comments electroSome 
1  Login

  Recommend  1 ⤤ Share Sort by Best

Start the discussion…

Be the first to comment.

ALSO ON ELECTROSOME WHAT'S THIS?

Custom Characters on LCD using PIC – Generating PWM with PIC Microcontroller
MikroC using Hi­Tech C
2 comments • 6 months ago 24 comments • 2 years ago

Interfacing EM­18 RFID reader with Using Push Button Switch – MPLAB XC8
Raspberry Pi 6 comments • a year ago
11 comments • 5 months ago

✉ Subscribe d Add Disqus to your site ὑ Privacy

RECENT COMMENTS

sir, one motor is working both on black and white path... i [..]

VRSHA (MAILTO:VARSHA.PANWAR9@GMAIL.COM)
on Line Follower Robot – without using Microcontroller (https://electrosome.com/line­follower­robot­without­
microcontroller/#comment­5061)

how can we connect a relay to this circuit

https://electrosome.com/interfacing­servo­motor­with­atmega32­microcontroller/ 6/11
7/15/2015 Interfacing Servo Motor with Atmega32 Atmel AVR Microcontroller

NASAR KHAN (MAILTO:EMAILTONASARKHAN@GMAIL.COM)
on Simple Water Level Indicator (https://electrosome.com/simple­water­level­indicator/#comment­5060)

Hi, Can you tell me the purpose of using HT12E & HT12D?

VISHWA (MAILTO:VISHWANATH.M90@GMAIL.COM)
on Water Level Indicator and Controller using PIC Microcontroller (https://electrosome.com/water­level­
indicator­controller­pic/#comment­5056)

Whats the voltage to get maximum range?

CHETHAN MURTHY (MAILTO:CHETHANMURTHYHS@GMAIL.COM)
on Wireless Transmitter and Receiver using ASK RF Module (https://electrosome.com/wireless­transmitter­
and­receiver­using­ask­rf­module/#comment­5054)

Its not a programmable IC

CHETHAN MURTHY (MAILTO:CHETHANMURTHYHS@GMAIL.COM)
on Wireless Transmitter and Receiver using ASK RF Module (https://electrosome.com/wireless­transmitter­
and­receiver­using­ask­rf­module/#comment­5053)

Hello sir can I add a water temperature sensor?

PANDAN (MAILTO:BRENDAN.2PARPAN@GMAIL.COM)
on Water Level Indicator and Controller using PIC Microcontroller (https://electrosome.com/water­level­
indicator­controller­pic/#comment­5046)

CAN U PLZ SHARE MORE PHOTOGRAPHS OF THIS PROJECT.... i mean how [..]

VRSHA (MAILTO:VARSHA.PANWAR9@GMAIL.COM)
on Line Follower Robot – without using Microcontroller (https://electrosome.com/line­follower­robot­without­
microcontroller/#comment­5045)

https://electrosome.com/interfacing­servo­motor­with­atmega32­microcontroller/ 7/11
7/15/2015 Interfacing Servo Motor with Atmega32 Atmel AVR Microcontroller

int count=1; if(button==0&&count==1) { led=1; count++; while(botton==0); }
if(button==0&&count==2) { led=0; count=1; [..]

KARTHI (MAILTO:KARTHIVOC6@GMAIL.COM)
on Using Push Button Switch with Atmega32 and Atmel Studio (https://electrosome.com/push­button­switch­
atmega32­microcontroller­atmel­studio/#comment­5044)

RECENT POSTS

GENERATING PWM WITH PIC MICROCONTROLLER – MPLAB XC8
(HTTPS://ELECTROSOME.COM/PWM­PIC­MICROCONTROLLER­MPLAB­XC8/)
BY (HTTPS://ELECTROSOME.COM/AUTHOR/LIJOPPANS/)LIGO GEORGE (HTTP://WWW.ELECTROSOME.COM)

GETTING STARTED WITH DIPTRACE (HTTPS://ELECTROSOME.COM/GETTING­
STARTED­WITH­DIPTRACE/)
BY FEBIN MATHEW (HTTPS://ELECTROSOME.COM/AUTHOR/FEBIN/)

INTERFACING EM­18 RFID READER WITH ARDUINO UNO
(HTTPS://ELECTROSOME.COM/EM­18­RFID­READER­ARDUINO­UNO/)
BY VIVEK KARTHA (HTTPS://ELECTROSOME.COM/AUTHOR/VIVEK_KARTHA/)

INTERFACING DS18B20 TEMPERATURE SENSOR WITH RASPBERRY PI
(HTTPS://ELECTROSOME.COM/DS18B20­SENSOR­RASPBERRY­PI­PYTHON/)
BY VIVEK KARTHA (HTTPS://ELECTROSOME.COM/AUTHOR/VIVEK_KARTHA/)

ACCESS RASPBERRY PI DIRECTLY FROM WINDOWS PC
(HTTPS://ELECTROSOME.COM/RASPBERRY­PI­ETHERNET­DIRECT­WINDOWS­
PC/)
BY VIVEK KARTHA (HTTPS://ELECTROSOME.COM/AUTHOR/VIVEK_KARTHA/)

INTERFACING EM­18 RFID READER WITH RASPBERRY PI
(HTTPS://ELECTROSOME.COM/EM­18­RFID­READER­RASPBERRY­PI/)
BY VIVEK KARTHA (HTTPS://ELECTROSOME.COM/AUTHOR/VIVEK_KARTHA/)

USING UART ON RASPBERRY PI – PYTHON (HTTPS://ELECTROSOME.COM/UART­RASPBERRY­PI­

https://electrosome.com/interfacing­servo­motor­with­atmega32­microcontroller/ 8/11
7/15/2015 Interfacing Servo Motor with Atmega32 Atmel AVR Microcontroller

PYTHON/)
BY VIVEK KARTHA (HTTPS://ELECTROSOME.COM/AUTHOR/VIVEK_KARTHA/)

CUSTOM CHARACTERS ON LCD USING PIC – MPLAB XC8
(HTTPS://ELECTROSOME.COM/CUSTOM­CHARACTERS­LCD­PIC­MPLAB­XC8/)
BY (HTTPS://ELECTROSOME.COM/AUTHOR/LIJOPPANS/)LIGO GEORGE (HTTP://WWW.ELECTROSOME.COM)

SUBSCRIBE US
EMAIL

SUBMIT

PRODUCTS

DC TO DC ADJUSTABLE BUCK CONVERTER
Rs.199.00
(HTTPS://ELECTROSOME.COM/SHOP/DC­BUCK­CONVERTER­LM2596S/)

LPG LNG GAS SENSOR MODULE ­ MQ6
Rs.350.00  Rs.299.00

(HTTPS://ELECTROSOME.COM/SHOP/LPG­LNG­GAS­SENSOR­MODULE­MQ6/)

WHITE SCREW MOUNT WHEEL 7X2CM
Rs.70.00  Rs.55.00

(HTTPS://ELECTROSOME.COM/SHOP/WHITE­SCREW­MOUNT­WHEEL­7X2/)

32.768KHZ CRYSTAL OSCILLATOR
Rs.5.00
(HTTPS://ELECTROSOME.COM/SHOP/32­768KHZ­CRYSTAL/)

https://electrosome.com/interfacing­servo­motor­with­atmega32­microcontroller/ 9/11
7/15/2015 Interfacing Servo Motor with Atmega32 Atmel AVR Microcontroller

GY­273 TRIPLE AXIS MAGNETOMETER
Rs.460.00  Rs.399.00

(HTTPS://ELECTROSOME.COM/SHOP/GY­273­TRIPLE­AXIS­MAGNETOMETER/)

CMOS VGA CAMERA MODULE ­ OV7670
Rs.1,200.00  Rs.899.00

(HTTPS://ELECTROSOME.COM/SHOP/CMOS­VGA­CAMERA­MODULE­OV7670/)

NORMALLY OPEN DOOR REED SWITCH
Rs.115.00  Rs.99.00

(HTTPS://ELECTROSOME.COM/SHOP/NORMALLY­OPEN­DOOR­REED­SWITCH/)

AIR QUALITY SENSOR MODULE ­ MQ135
Rs.450.00  Rs.429.00

(HTTPS://ELECTROSOME.COM/SHOP/AIR­QUALITY­SENSOR­MODULE­MQ135/)

SUBSCRIBE US

SUBMIT

electroSome
Like Page

Follow 589

 (https://electrosome.com)

https://electrosome.com/interfacing­servo­motor­with­atmega32­microcontroller/ 10/11
7/15/2015 Interfacing Servo Motor with Atmega32 Atmel AVR Microcontroller

 (https://www.positivessl.com)

Terms and conditions (https://electrosome.com/terms­conditions/) / 
Privacy Policy (https://electrosome.com/privacy­policy/) / Shipping Policy (https://electrosome.com/shipping­policy/) / 
Refund Policy (https://electrosome.com/refund­policy/) / About Us (https://electrosome.com/about­us/)
electroSome ­ Discover... Develop... Deliver...

https://electrosome.com/interfacing­servo­motor­with­atmega32­microcontroller/ 11/11

Вам также может понравиться