In this video, we will be learning about L293D and how to use it.
First of all, let's look at the pin arrangement.


Next, let's understand how the IC controls the direction of motor spin. Refer the simple diagram below for better understanding.

As you can see in the diagram above, PIN 3 and 6 is connected to the same DC motor. Depending on the input received in INPUT 1 and 2, PIN 3 and 6 will then change its polarity to influence the direction of motor spin.
For instance, if
INPUT 1 = HIGH
INPUT 2 = LOW, motor will turn clockwise
Else
INPUT 1 = LOW
INPUT 2 = HIGH, motor will turn anticlockwise.
Next, let's move on to how we can create the components for our tutorial. Refer schematic below :

In the diagram above, I am using two DC motor with a joystick to control the motor's spin direction.
Once the circuit has been connected as shown above, you can upload the below code :
int output_speed = A2;
void setup() {
// put your setup code here, to run once:
Serial.begin (9600);
pinMode (x_key, INPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode (output_speed, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int x_pos = analogRead(x_key);
Serial.print("X Position : ");
Serial.println(x_pos);
if (x_pos < 600 && x_pos > 400)
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
if (x_pos < 400 )
{
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
if (x_pos > 600 )
{
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
}
With that, we can conclude this tutorial. Good Luck Trying. If you have any questions, feel free to post it in the comment section below. I will try my best to help.
Check out my YouTube video below on L293D motor :
Comments