Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

How to interface Servo Motor with AVR Microcontroller (ATmega16)- (Part 21/46)

By Ashutosh Bhatt

Servo motors find huge applications in industries in the field of automation, control & robotics. The servo motors are well known for their precise control and work on the principle of servo mechanism. The servo motors can be made to run at precise angle using PWM. The PWM (pulse width modulation) is the basic working principle behind a servo motor (For more details about PWM refer Phase correct PWM mode). This article explores the interfacing of servo motor with ATmega16. Also to know more about servo mechanism see Interfacing Servo Motor with 8051.

 


 

 
There are different types of servos available in the market. This article bounds its scope to interfacing a commonly available servo, widely used by hobbyist with ATmega16. Such a servo consists of three wires positive supply, ground and a control signal. Unlike other motors, Servo motors don’t require any driver. When a PWM signal is applied to its control pin the, the shaft rotates to a specific angle depending on the duty cycle of the pulse.
 

Duty Cycle of Pulse

Fig. 2: Duty Cycle of Pulse and Angular Displacement of shaft on applying PWM wave
 
In the above figure the ON time for pulse is 1ms and off time pulse is 18ms this rotates the shaft to -90 degree. Similarly if the on time of pulse is 1.5ms and the off time of pulse same the servo rotates to 00 and if ON time pulse increases to 2ms it rotates to +900. This gives a complete 180 degree rotation. The motor maintains its position for every corresponding signal.
 
Note: Before starting with servo first check the lowest ON pulse which rotates servo to -90 degree and the highest ON pulse which rotates the servo to +90 degree while keeping the OFF pulse constant. While experimenting with VS2 servo motors it was found that for -90degree the ON pulse required was 50us and OFF pulse was 18ms. And for +90 degree the ON pulse was 2050us and keep the OFF time same as 18ms. Things may differ on the type and quality.
 
A continuous pulse of 50 us ON time and 18ms OFF time rotates the axis of servo to -90 degree.

while(1)
{
Motor =(1<<servo);
_delay_us(50);
Motor = (0<<servo);
_delay_ms(18);
}
If the ON time is increased the rotation angle also increases.
The given code rotates the servo axis by 20 degree after every 5 sec.

 

Project Source Code

###


// Program to rotate servo at the step of 20 degree.
#include<avr/io.h>
#include<util/delay.h>
 
#define motor PORTD
#define servo PD6
 
void degree(unsigned int );
 
int main(void)
{
unsigned int degree_value,time;
DDRD=0b01000000;
for(degree_value=0;degree_value<180;degree_value +=20)
for(time=0;time<50;time++)
{
degree(degree_value);
}
return 0;
}
 
void degree(unsigned int k)
{
k=50+(k*10);
motor= (1<< servo);
_delay_us(k);
motor = (0<<servo);
_delay_ms(18);
}
 

###

 


Circuit Diagrams

Circuit-Diagram-of-How-to-interface-Servo-Motor-with-AVR-Microcontroller-ATmega16

Project Components

  • ATmega16

Project Video


Filed Under: AVR Microcontroller
Tagged With: atmega16, avr, microcontroller, motor, servo motor
 

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Designing Gate Driver Circuit and Switching Mechanism for Modified Sine Wave Inverter – (Part 9/17)
  • Completing Modified Sine Wave Inverter Design with Full Bridge Circuit and Step Up Transformer – (Part 10/17)
  • Designing an Offline UPS – Part (12 /17)
  • How to reduce Switching Time of a Relay – (Part 15/17)
  • Testing MOSFET – (Part 16/17)
  • Driving High Side MOSFET using Bootstrap Circuitry – (Part 17/17)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • MicroPython – I2C protocol in ESP8266 and ESP3
  • New automotive radar sensor enables reliable in-cabin monitoring system
  • TI breaks ground on 300-mm semiconductor wafer-fabrication plants in Texas
  • New wireless AR Smart Viewer reference design
  • Infineon launches scalable and wireless charging platform with configurable controllers

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd ldr led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • What's the deal with all these "MPPT" IC's with no current sense?
  • Photovoltaic MOSFET Drivers - Voltage Rating
  • Impedance requirement for SDRAM signals
  • A circuit that can adjust a resistance and probing a voltage node
  • A analogue circuit that spit out the resistance desired

RSS Electro-Tech-Online.com Discussions

  • IRS2453 the H circuit
  • Ampro 16mm Stylist projector woes.
  • How to quickly estimate lead acid battery capacity ?
  • Finally switched to Linux.
  • Multistage BJT amplifier
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering