DC motor interfacing with atmega32 and L293

INTERFACING DC MOTOR WITH ATMEGA32,In this article you will learn how to interface DC motor with Atmega32. You will also learn what L293 is and how to use IC L293 with Atmega32. This article will surely helps you in controlling two motors at a time with the help of L293.

WHAT IS L293 Motor driver?

L293 is a most popular and less expensive built-in H-bridge in a small integrated circuit used for low current motors. H-bridge is a motor driving unit used to control the direction of two motors at a time either clockwise or anticlockwise direction. It is a16 pin IC in which pins out1, out2, out3 and out4 are connected to two motors. Pin EN1 & EN2 are PWM pins while IN1, IN2, IN3 & IN4 are used to provide signals to the motors.

L293 dc motor driver
L293 dc motor driver


The circuit on proteus is shown in the figure given below:

dc motor speed control circuit diagram
dc motor speed control circuit diagram

To make the circuit on proteus, select Atmega32, L293 IC, crystal, DC motor and rest of the components from built-in library.

  • Connect the IN1, IN2, IN3 & IN4 pins of L293 with PB0, PB1, PB2 & PB3 pins of Atmega32.
  • Pin EN1 & EN2 pins of L293 are connected to 5V
  • Connect the VCC with 12V and GND pins of L293 with ground.
  • Set the frequency of crystal and Atmega32 to 16MHz.

The below truth table will help you to develop understandings with the basic movements of motors for building a code.


0 0 Both Motors stop
0 1 Motors move in anticlockwise direction
1 0 Motors move in clockwise direction
1 1 Both Motors stop



We use Atmel studio 6 for coding and the code was developed in C language.

#ifndef F_CPU

#define F_CPU 16000000UL // 16 MHz clock speed



#include <avr/io.h>        //standard AVR library

#include <util/delay.h>     // delay library


int main(void) //main starts


DDRB= 0xFF; // direction of port B as output

while(1)   //infinite loop


PORTB = 0x05; // motor rotation in clockwise direction

_delay_ms(3000);    //delay of 3 sec


PORTB = 0x00;// motor stopped

_delay_ms(1000);    //delay of 1 sec


PORTB = 0x0A; //motor rotation in anticlockwise direction

_delay_ms(3000);    //delay of 3 sec


PORTB = 0x00;// motor stopped

_delay_ms(1000);    //delay of 1 sec


}     //while loop end

}      //main end



As motors are connected to first four pins of PORTB that’s why we make the direction of PORTB as output by using command (DDRB). The comments are shown after “//”.  First motor will rotate in clockwise direction by setting PB.0 & PB.2 high for 3 seconds and then both motors stops for one second by setting all four pins to low. For anticlockwise direction set PB.3 & PB.1 high. The code will execute infinite times due to while loop.

dc motor code
dc motor code


To observe the functionality of the circuit according to given code, dump the HEX file of the code in circuit and see the simulation results.

dc motor interfacing with atmega32 microcontroller  simulation
dc motor interfacing with atmega32 microcontroller simulation


There are several applications of DC motors. They can be used in different robots having wheels and robotic cars to move in different directions. Especially for line following robots (LFR) use of DC motors is very common

2 thoughts on “DC motor interfacing with atmega32 and L293”

Leave a Comment