Welcome back to SmartBlogging🌏.
To start with Robotics, first thing you should learn is controlling different types of motors. So will start again with basics of motors and how to control motor by arduino as per your requirement. To start with basics of board, please go through my previous blog Led- blinking-with-arduino-boards.
To start with Robotics, first thing you should learn is controlling different types of motors. So will start again with basics of motors and how to control motor by arduino as per your requirement. To start with basics of board, please go through my previous blog Led- blinking-with-arduino-boards.
Components Required:
- Arduino Uno
- L293D
- https://www.amazon.in/Robo-India-L293D-2-Pieces-Driver/dp/B01GUV33SI
- https://www.electronicscomp.com/l293d-motor-driver-board
- https://www.electroncomponents.com/L293D-H-Bridge-Motor-Driver
- Small DC motor
- https://www.amazon.com/slp/mini-dc-motor/78ytbxcv9pfo5nq
- https://www.flipkart.com/numex-12-volt-dc-motor-multicolor/p/itmf2vna2fhuc6j5
- Bread board
- USB Cable
- Jumper wires
Circuit Diagram:
The maximum current of an Arduino I/O port is 20mA but the drive current of a motor is at least 70mA. Therefore, we cannot directly use the I/O port to drive the current; instead, we can use an L293D to drive the motor. L293D L293D is designed to provide bidirectional drive currents of up to 600mA at voltages from 4.5V to 36V. It's used to drive inductive loads such as relays, solenoids, DC and bipolar stepping motors, as well as other high-current/high-voltage loads in positive-supply applications.
See the figure of pins below. L293D has two pins (Vcc1 and Vcc2) for power supply. Vcc2 is used to supply power for the motor, while Vcc1, for the chip. Since a small-sized DC motor is used here, connect both pins to +5V. If you use a higher power motor, you need to connect Vcc2 to an external power supply.
The Enable pin 1,2EN of the L293D are connected to 5V already, so L293D is always in the working state. Connect pin 1A and 2A to pin 9 and 10 of the control board respectively. The two pins of the motor are connected to pin 1Y and 2Y respectively. When pin 10 is set as High level and pin 9 as Low, the motor will start to rotate towards one direction. When the pin 10 is Low and pin 9 is High, it rotates in the opposite direction.
Coding:
- Build the circuit as shown above.
- Copy the below code into software IDE.
//DC Motor Control
//The DC motor will begin rotating left and right, and its speed will vary accordingly.
//Email:blog2vin@gmail.com
//Website:www.blog2vin.com
const int motorIn1 = 9; //attach to one of the pin of the motor
const int motorIn2 = 10; //attach to another pin of the motor
void setup()
{
pinMode(motorIn1,OUTPUT); //initialize the motorIn1 pin as output
pinMode(motorIn2,OUTPUT); //initialize the motorIn2 pin as output
}
void loop()
{
clockwise(200); //rotate clockwise
delay(1000); //wait for a second
counterclockwise(200); //rotate counterclockwise
delay(1000); //wait for a second
}
//The function to drive motor rotate clockwise
void clockwise(int Speed)
{
analogWrite(motorIn1,Speed); //set the speed of motor
analogWrite(motorIn2,0); //stop the motorIn2 pin of motor
}
//The function to drive motor rotate counterclockwise
void counterclockwise(int Speed)
{
analogWrite(motorIn1,0); //stop the motorIn1 pin of motor
analogWrite(motorIn2,Speed); //set the speed of motor
}
----------------------------------------END-----------------------------
//The DC motor will begin rotating left and right, and its speed will vary accordingly.
//Email:blog2vin@gmail.com
//Website:www.blog2vin.com
const int motorIn1 = 9; //attach to one of the pin of the motor
const int motorIn2 = 10; //attach to another pin of the motor
void setup()
{
pinMode(motorIn1,OUTPUT); //initialize the motorIn1 pin as output
pinMode(motorIn2,OUTPUT); //initialize the motorIn2 pin as output
}
void loop()
{
clockwise(200); //rotate clockwise
delay(1000); //wait for a second
counterclockwise(200); //rotate counterclockwise
delay(1000); //wait for a second
}
//The function to drive motor rotate clockwise
void clockwise(int Speed)
{
analogWrite(motorIn1,Speed); //set the speed of motor
analogWrite(motorIn2,0); //stop the motorIn2 pin of motor
}
//The function to drive motor rotate counterclockwise
void counterclockwise(int Speed)
{
analogWrite(motorIn1,0); //stop the motorIn1 pin of motor
analogWrite(motorIn2,Speed); //set the speed of motor
}
----------------------------------------END-----------------------------
- Copy the above code to Arduino software IDE and compile for errors.
- Dump the code to Arduino board. For detailed instructions on using IDE go through this post https://www.blog2vin.com/led-blinking-with-arduino-boards.
- If "Done uploading" appears at the bottom of the window, it means the sketch has been successfully uploaded.
- Now, the blade of the DC motor will begin rotating left and right, in a speed that varies accordingly.
Facebook page : https://www.facebook.com/Blog2Vin-107230150942512/
Instagram page : https://www.instagram.com/blog2vin/
Email : blog2vin@gmail.com
Youtube : https://www.youtube.com/channel/UCpiKh6NDIjSR1ptistW9u2w
Website : https://www.blog2vin.com/
It's very informative
ReplyDeleteThank you
Delete