How Arduino L293D motor shield works with simulation in Proteus

 In this tutorial, we will take a closer look at how an Arduino L293D motor shield works. The L293D is a popular motor driver IC that can be used to control DC motors, stepper motors, and other types of motors. When combined with an Arduino microcontroller, it can be used to create various types of robotic projects such as robotic cars, robots, and more.

We will be discussing the pinout, circuit diagram, and working principle of the L293D motor shield. We will also be showing you how to connect the shield to an Arduino microcontroller and how to write a code to control the motors.

By the end of this tutorial, you will have a good understanding of how the Arduino L293D motor shield works and how it can be used to control motors.

Here it is shown the working principle and operation of control of DC motors with Arduino and L293D motor shield with the help of circuit simulation in Proteus. It is also illustrated how to use serial port with L293D motor shield in proteus. The L293D motor can be used to control servo motors, dc motors and stepper motors. Here we will illustrate how to drive two dc motors with the motor shield in Proteus.

How Arduino L293D motor shield works

The following is the circuit diagram of driving the L293D motor shield with Arduino Uno.Arduino L293D driver


 The following is the L293D motor shield.

L293 motor shield

As shown in the above diagram, 2 servo motors and 4 DC motors are connected. The motor driver has two mainly three IC(Integrated Circuit). Two of them are L293D motor driver and one is the 74HC595 Shift Register IC. These three chips are controlled with microcontroller like Arduino Uno. These chips on actual L293D motor shield is shown below.

DK electronics L293D motor shield

The following shows the pins of the Arduino Uno that is wired to the two L293D motor driver and 74HC595 shift register.


The 74HC595 shift register is used to control the direction aspect of the motors. The arduino pins PB4, PB0, PD7, PD4 connected to DIR_LATCH, DIR_SER, DIR_EN and DIR_CLK are connected to the 74HC595 ST_CP, DS, OE and SH_CP pins as shown below.

The output M1A, M1B, M2A, M2B, M3A, M3B, M4A and M4B of the 74HC595 are connected to the two L293D motor drivers as shown below.



One L293D motor driver speed is controlled using the Arduino Timer 0 PWM pins 5 and 6 and the other L293D motor driver speed is controlled using the Arduino Timer 2 PWM pins 3 and 11. Each of the L293D IC on the motor shield has two H bridge and hence the motor shield has total of 4 H bridge. The H bridge is used to control the direction of rotation of motors. See the tutorial DC Motor with BJT H-bridge motor driver to learn how H bridge controls motor direction of rotation.

The Arduino Timer 1 PWM pins 9 and 10 is used for servo control.

Arduino L293D motor shield simulation in Proteus

Here Arduino L293D motor shield simulation is illustrated in proteus. This  is helpful in understanding how the motor shield works. The circuit was explained above and now we will how the motor shield works with simulation. For purpose of illustration two DC motors connected to the M3  and M4 ports.

Motor connection of L293D motor driver shield

 Then these motors are rotated to simulate the remote controlled car. The commands are given via the serial port of Arduino. The commands are forward, backward, left, right and stop. These commands are sent via tera term to virtual port emulator to the proteus compim then to Arduino and finally to the motor drivers.

To follow this tutorial you must have a serial terminal like tera term and virtual serial port emulator. Then you have to configure the com port and baud rate in order to send commands from serial port to proteus. How to do is explained in details in the tutorial Serial communication from PC to Proteus.

Watch the following video for motor shield simulation in proteus.


The Arduino code for L293D motor shield is below.

#include <AFMotor.h>

AF_DCMotor backleftmotor(3);
AF_DCMotor backrightmotor(4);

void setup(){
  mstop();
  Serial.begin(9600);
}

void loop(){
  if(Serial.available()){
      char cmd = Serial.read();
      switch(cmd){
        case 'F':
          forward();
          break;

        case 'B':
          backward();
          break;

		case 'L':
			left();
			break;

		case 'R':
			right();
			break;

        case 'A':
          accelerate();
          break;

        case 'd':
          deaccelerate();
          break;

        case 'S':
          mstop();
          break;

        default:
          break;
      }
    }
}

void forward(){
  backleftmotor.setSpeed(200);
  backrightmotor.setSpeed(200);
  backleftmotor.run(FORWARD);
  backrightmotor.run(FORWARD);
  }

void backward(){
  backleftmotor.setSpeed(200);
  backrightmotor.setSpeed(200);
  backleftmotor.run(BACKWARD);
  backrightmotor.run(BACKWARD);
  }

void left(){
      backrightmotor.run (FORWARD);
      backleftmotor.run (BACKWARD);
    }

void right(){
      backrightmotor.run (BACKWARD);
      backleftmotor.run (FORWARD);
    }

void accelerate(){
  backleftmotor.run(FORWARD); 
  backrightmotor.run(FORWARD); 

    uint8_t i;

    for (i=0; i<255; i++){
    backleftmotor.setSpeed(i); 
    backrightmotor.setSpeed(i); 
    delay(10);
    }
}

void deaccelerate(){
  backleftmotor.run(FORWARD); 
  backrightmotor.run(FORWARD); 

  uint8_t i;
  for(i=255; i!= 0; i--){
    backleftmotor.setSpeed(i); 
    backrightmotor.setSpeed(i);  
    delay(10);
    }
}

void mstop(){
   backleftmotor.run(RELEASE); 
    backrightmotor.run(RELEASE);
  } 

So here we have illustrated with simulation how DC motor control using L293D Motor Shield and Arduino works.

 

Post a Comment

Previous Post Next Post