# How to Use a L293D Chip With Arduino and a Motor

2,593

41

3

Lets control an DC Motor with a L293D Chip and Make it so it will go clockwise or counter clockwise.

I received a kit from GearBest that included all the parts I needed for this project and recommend it to you if you are just starting with Arduino, You can check it out here!

The parts you will need are:

1) Arduino Board with PWM

2) L293D Motor Driver

3) Wires

4) External Power Supply (not needed but recommended)

5) 10 minutes

Lets Begin!

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Wire Everything!

Now were going to wire everything.

I created the schematic to make it easier to understand, then used that for reference when wiring it. Its super simple!

For people that cant see the picture notes:

In the schematic the bottom wire from the chip is the one you would connect to the power supply positive, i didn't add it to keep things simple.

## Step 2: Code the Arduino

The code is super simple, we use "for" statements and "analogWrite" to control it.

For Example:

when pin 5 is low and pin 6 is high it will rotate clockwise

or

when pin 5 is high and pin 6 is low it will rotate counter-clockwise

Here is the code also:

```void setup() {

}

void loop() {
for(int i = 0; i<255; i++){
analogWrite(5, i);
analogWrite(6, 0);
delay(5);
}
for(int i = 0; i<255; i++){
analogWrite(5, 255-i);
analogWrite(6, 0);
delay(5);
}
for(int i = 0; i<255; i++){
analogWrite(5, 0);
analogWrite(6, i);
delay(5);
}
for(int i = 0; i<255; i++){
analogWrite(5, 0);
analogWrite(6, 255-i);
delay(5);
}
}```

## Step 3: Test It Out!

Your motor should now get increasingly faster then decelerate reverse direction and repeat!

If you have any questions leave them in the comments and i will try to help you out.

Hope you enjoyed

Participated in the
Maker Olympics Contest 2016

## Recommendations

• ### Internet of Things Class

22,766 Enrolled

## 3 Discussions

thanks, I actually accidentally had the motor attach to the speaker and thought "hey this is really useful". now I use it a lot

the rest if your instructable too :)