Arduino Projects    |   Raspberry Pi  |     Electronic Circuits   |   Electronics Reference Design Library  |   AVR    |    PIC    |    8051    |    Electronic Projects

How to interface Servo Motor with 8051 Microcontroller (AT89C51)

Summary

Developed By: 
Himanshu Choudhary
This project demonstrates the operation of a servo motor. The control signals for the rotation of the motor are provided by 8051 microcontroller (AT89C51). Here, the servo arm is rotated by 5° from the previous position, starting from 0 °as initial position. As the servo reaches a limit, the arm comes back to the initial position (0°). For basic concepts and know-how of a servo motor, refer to the article Servo Motor.
 
8051 Microcontroller Servo Motor Project

Description

The servo motor is controlled by feeding pulse width modulated (PWM) signal at the control wire of the servo motor. In addition a 4.8V (ideally 5V) DC supply is provided to the red lead of the servo. The black lead of the servo is connected to Ground.

The first pin of port P1 (P1^0) of AT89C51 microcontroller is set as the output pin to provide control signal to the servo motor. Before connecting to the control wire of servo, the output from the microcontroller is fed through a comparator IC (LM324) so that the signal is protected from any loss due to overloading.

In the program, one of the 8051 timers is configured to generate flag after every 50 µs. Usually the pulse durations corresponding to 0° and 180° angular positions are 1ms and 2ms, but these durations may vary for different servos. Here, a pulse with ON time of 700 µs sets the motor closer to 0° and a pulse of 5500 µs sets the motor to 180°. A variable is taken which is initialized to a value 14. A function using timer is written that has the variable mentioned above as an argument. This function generates time delay in the multiples of 50 µs. Initially when the microcontroller executes program, a pulse with ON time of 700 µs (14 x 50 µs) followed by OFF time of 18 ms is generated. This shifts the servo horn to 0° angle.
 
 
Every time the value of variable is increased by 5. This increases the ON time of pulse by 250 µs (5 x 50 µs). So every new pulse has an ON time 250 µs greater than the previous one. This is followed by an OFF time of 18 ms. In this way, at every loop the servo is rotated by 5° ahead.
As the value of variable reaches above 100 it is again set to 14. This moves the servo back to the initial position of 0° after a full rotation.
 

Circuit Diagram

Video

Code

This Code is only visible to Registered users. Please Login/Register

 

Components

LM324 | LM324N Datasheet
IC LM324

LM324 is a 14pin IC consisting of four independent operational amplifiers (op-amps) compensated in a single package. Op-amps are high gain...

AT89C51 Microcontroller, Atmel 89C51 Controller Image
AT89C51 Microcontroller

AT89C51 is an 8-bit microcontroller and belongs to Atmel's 8051 family. ATMEL 89C51 has 4KB of Flash programmable and erasable read only memory (...

Browse 4m+ Electronic Products


 
Pick the right product for your next design project with "Mouser Store". Mouser Electronics brings broadest range of semiconductors and electronic components from over 500 industry leading suppliers. 
 
Mouser specializes in the rapid introduction of new products and technologies for design engineers and buyers that includes semiconductors, interconnects, passives, and electro-mechanical components. Providing the best possible service with the flexibility of not requiring a minimum order and same-day shipping, Mouser has it all.
 
 
 
 
When you need the right part right now, think of Mouser
 
Thank you
Team EG

 

You are here