Interfacing DC Motor with Atmega32 Microcontroller
Contents
In some of your electronic projects you may want to control a DC Motor with Atmega32 Microcontroller. We can’t connect a DC Motor directly to a microcontroller due to following reasons.
- A microcontroller can’t supply the current required for the working of DC Motor. ATmega32 Microcontroller can source or sink currents up to 40mA but a DC Motor needs current very much more than that.
- The negative voltages created due to the back emf of the motor may affect the proper functioning of the microcontroller.
- You may need to control the direction of rotation of the motor by changing the polarity of  the motor supply.
- The operating voltage of the DC Motor may be much higher than the operating voltage of the microcontroller.
To solve these problems you may use transistorized H Bridge in which freewheeling diodes are used to avoid problems due to back emf. Thus it requires minimum four transistors, diodes and resistors for each motor. It is better to use readymade ICs such as L293D or L293 instead of making your own H Bridge, which simplifies your project.
L293D is a Quadruple Half H-Bridge driver commonly used for motor driving. We needn’t connect any transistors, resistors or freewheeling diodes. All the four outputs of this IC are TTL compatible and output clamp diodes are provided to drive inductive loads. L293D can provide up to 600mA current, in the voltage raging from 4.5 to 36v. L293 is a similar IC which can provide up to 1A in the same voltage range.
L293 or L293D contains four Half H Bridge drivers and are enabled in pairs. Input EN1  is used to enable pair 1 (IN1-OUT1, IN2-OUT2) and input EN2 is used to enable pair 2 (IN3-OUT3, IN4-OUT4). We can drive two DC Motors with one L293D, but here for demonstration we are using only one. You can connect second DC Motor to driver pair 2 according to your needs.
Circuit Diagram
Motor Supply is given to the Vs pin of L293D and motor is connected to the first pair of drivers, which is enabled by connecting EN1 to logic HIGH. Vss pin is used to provide logic input to L293D. Â Control signals is given by using Atmega32 microcontroller which operates at 5V, hence Vss is connected to 5V.
Atmel Studio C Program
#ifndef F_CPU #define F_CPU 8000000UL // 16MHz clock speed #endif #include <avr/io.h> #include <util/delay.h> int main(void) { DDRC = 0xFF; //PORTB as Output while(1) { //Rotates Motor in Antilockwise PORTC = 0x01; //00000001 _delay_ms(4000); //Stops Motor PORTC = 0x00; //00000000 _delay_ms(4000); //Rotates Motor in Clockwise PORTC = 0x02; //00000010 _delay_ms(4000); //Stops Motor PORTC = 0x03; //00000011 _delay_ms(4000); } }
Control Signals and Motor Status
PC0/IN1 | PC1/IN2 | Motor Status |
---|---|---|
LOW | LOW | Stops |
LOW | HIGH | Clockwise |
HIGH | LOW | Anti-Clockwise |
HIGH | HIGH | Stops |
You can download Atmel Studio files and Proteus files here…
Interfacing DC Motor with Atmega32 Microcontroller using L293D