A motor is the basic building block of robotics and if you are learning Arduino then learning to connect a motor to it is very much important. Today we will be doing so using L293D ic. An L293D motor driver IC is really important. Otherwise, it will burn your Arduino. Also, this IC allows you to change the direction of how the motor rotates without shifting the battery terminals.
Step 1: Things You Need
- DC motor
- Jumper Wires
- 9v Battery
Step 2: L293D IC
The most interesting part of this project is the L293D IC. This is actually an H Bridge and the use of it is to change the polarity of the voltage thus allowing us to reverse the direction of the motor rotation. As given in the picture above there are 8 pins on either side. Each side can control one motor and in total we can control two motor using one IC.
The first pin on the left side is the enable pin and a 5v supply is given to it.
The second pin is input pin and is connected to digital i/o pin of the Arduino
Output1 is connected to any one of the motor wire.
Both GNDs are connected to ground.
Output2 is connected to the other wire of the motor.
Input2 is connected to another digital i/o pin.
Vs is the most important part as the power supply to the motor is given to it. This means that the motor cannot be powered by the arduino alone and we need to have a 9v battery so that the motor can rotate.
A detailed circuit diagram is also given above.
Step 3: Code
The code is given below.
Your next goal is to connect it with an ultrasonic sensor. If you have any doubt please check my previous instructable on controlling LED with ultrasonic sensor.