L293D, H Bridge Arduino


L293D is a DC motor controller.

Below Arduino code to use it.

unsigned char table[128] = {0};

int motor1_A=6;
int motor1_B=5;
int motor1_Speed=3;              

void setup()
{  
  pinMode(motor1_A,OUTPUT);
  pinMode(motor1_B,OUTPUT);
}

void loop()
{
  // motor1
  for (int i=0; i<256; i+=1){
    digitalWrite(motor1_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
    digitalWrite(motor1_B,LOW);
    analogWrite(motor1_Speed,i); // speed counts from 0 to 255
    delay(20);
  }
  for (int i=255; i>0; i-=1){
    digitalWrite(motor1_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
    digitalWrite(motor1_B,LOW);
    analogWrite(motor1_Speed,i); // speed counts from 0 to 255
    delay(20);
  }
}