1
V1.0
DC Motor
Overview
Specification
Motor:
Rated Voltage: DC 6V za
This lesson will teach you how to control the DC motor to turn, reverse and stop.
ra
Speed: 5000 RPM
L293d:
Please view [Link].
Path: \Public_materials\Datasheet\ L293d -[Link]
Pin definition
sm
Hardware required
Material diagram Material name Number
DC Motor 1
---Designed by Smraza Keen
2
V1.0
IC L293D 1
USB Cable 1
UNO R3 1
Breadboard 1
Jumper wires Several
za
Connection diagram
ra
sm
Connection:
---Designed by Smraza Keen
3
V1.0
za
ra
Note:
Pay attention to the direction of the IC L293D.
sm
Sample code
Note: sample code under the Sample code folder
#define ENABLE 3
#define DIRB 4
#define DIRA 5
int i;
void setup()
{
//---set pin direction
pinMode(ENABLE,OUTPUT);
pinMode(DIRA,OUTPUT);
pinMode(DIRB,OUTPUT);
[Link](9600);
}
void loop()
{
//---back and forth example
---Designed by Smraza Keen
4
V1.0
[Link]("One way, then reverse");
digitalWrite(ENABLE,HIGH); // enable on
for (i=0;i<5;i++) {
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(500);
digitalWrite(DIRA,LOW); //reverse
digitalWrite(DIRB,HIGH);
delay(500);
}
digitalWrite(ENABLE,LOW); // disable
delay(4000);
[Link]("fast Slow example");
za
//---fast/slow stop example
digitalWrite(ENABLE,HIGH); //enable on
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(1000);
digitalWrite(ENABLE,LOW); //slow stop
ra
delay(3000);
digitalWrite(ENABLE,HIGH); //enable on
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(1000);
digitalWrite(DIRA,LOW); //fast stop
sm
delay(3000);
//[Link]("PWM full then slow");
//---PWM example, full speed then slow
digitalWrite(ENABLE,HIGH); //enable on
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(2000);
analogWrite(ENABLE,128); //half speed
delay(2000);
digitalWrite(ENABLE,LOW); //all done
delay(10000);
}
Language reference
Null
---Designed by Smraza Keen
5
V1.0
Application effect
You will see the DC motor will be turning, turning and stopping.
za
ra
sm
---Designed by Smraza Keen