loading

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!

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

You can download the code from here

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

that speaker stabilizing solution is great!!
thanks, I actually accidentally had the motor attach to the speaker and thought &quot;hey this is really useful&quot;. now I use it a lot
the rest if your instructable too :)

About This Instructable

2,009views

35favorites

License:

Bio: I like to create new things! I'm very interested in IOT and just Internet Stuff. I am not responsible for any injury or deaths ... More »
More by Funguypro:See Through Buildings With a Drone Dog Water Alarm (V2) Custom PCB's With a Laser Cutter 
Add instructable to: