Code ya Arduino mpe Video: Contrôleur ya moteur DC L293D (ezali na contrôle ya vitesse te)
Lithu eye ya kolandela ndenge ya kosalela contrôleur ya moteur L293D na Arduino mpo na kokamba moteur ya courant continu. L293D e pesaka yo nzela ya kopelusa moteur na ngambo mibale: na ngonga ya ngonga mpe na ngonga ya ngonga. Na kolanda malako oyo, okoyekola ndenge ya kosala câblage ya ba composants mpe ya kosala programme ya Arduino mpo na kozwa contrôle ya moteur oyo olingi.
Na projet oyo, tokosalela driver ya moteur L293D mpo na kokamba moteur moko ya courant continu. Moteur akokoka kobongola direction kolanda ba commandes oyo ekomami na code ya Arduino. Mpo na kososola malamu mise en place mpe code, ezali malamu kotala vidéo oyo elandi (na vidéo na 00:00).
Matériel oyo esengeli
L293D ezali circuit intégré oyo esalelami mpo na kokamba ba moteurs. Ekoki kokamba ba moteurs mibale ya courant continu na mbala moko to moteur moko ya stepper. Chip oyo esalelaka configuration ya H-bridge mpo na kopesa nzela ya contrôle ya direction na kobongola polarité ya tension oyo epesameli moteur. Flexibilité oyo esalaka ete ezali choix ya malamu mpo na ba projets ya robotique mpe automatisation.
Na libanda ya L293D, tokosalela carte Arduino mpo na kotinda ba signaux ya contrôle na driver ya moteur. Arduino ekobimisa ba niveaux ya logique oyo esengeli mpo na kopesa nzela na moteur mpe koyeba direction ya libale na yango. Mise en place ekosenga mpe moteur ya courant continu mpe source ya courant oyo ekokani na ba exigences ya tension ya moteur.
Détails ya Datasheet
| Fabricant | Texas Instruments |
|---|---|
| Numéro ya pièce | L293D |
| Tension ya logique/IO | 5 V |
| Tension ya alimentation | 4.5 - 36 V |
| Courant ya sortie (na canal) | 600 mA |
| Courant ya pointe (na canal) | 1.2 A |
| Directive ya fréquence PWM | 20 kHz |
| Seuils ya logique ya entrée | 2.5 V (typ.) |
| Chute ya tension / RDS(on) / saturation | 1.5 V (max) |
| Limites thermiques | 150 °C (max) |
| Package | 16-DIP |
| Notes / variantes | Ekoki kokamba ba moteurs mibale |
- Kokamba ete tension ya alimentation eleka te 36 V.
- Salela ba moyens ya kopelisa ntango ozali kosalela na pembeni ya courant maximum.
- Kokamba tango nyonso ete ground ya Arduino mpe driver ya moteur esangani.
- Vérifier câblage mpo na kokima ba connexions ya polarité oyo ebaloli.
- Salela ba signaux PWM mpo na kokamba vitesse soki esengeli na ba projets ya mikolo ekoya.
Instructions ya Câblage


Mpo na kosala câblage ya contrôleur ya moteur L293D na Arduino, banda na kosangisa courant mpe ground. Singa pin 4 mpe pin 5 ya L293D na ground. Na nsima, singa pin 1 (Vcc1) na sortie 5 V ya Arduino. Mpo na Vcc2 (pin 8), singa yango na source ya courant ya libanda, mpe kotala ete ekokani na spécification ya tension ya moteur.
Na nsima, singa pin ya enable (pin 1) na pin 8 ya Arduino mpo na kokamba courant ya moteur. Mpo na ba entrées ya contrôle ya moteur, singa pin 2 (1A) ya L293D na pin 2 ya Arduino mpe pin 7 (2A) na pin 7 ya Arduino. Na suka, singa ba terminaux ya moteur na pin 3 (1Y) mpe pin 6 (2Y) ya L293D.
Ba Exemples ya Code & Explication
Code oyo elandi ebandisaka ba pins mpe esalaka mise en place ya contrôle ya moteur. Ba identifiants oyo esalelami ezali P1A mpo na pin ya liboso ya contrôle ya moteur mpe EN12 mpo na pin ya enable. Fonction ya setup esalaka ba pins lokola ba sorties.
void setup() {
Serial.begin(9600); // mise en place ya Serial Monitor mpo na kolakisa information
pinMode(P1A, OUTPUT); // définir pin lokola OUTPUT mpo na P1A
pinMode(P2A, OUTPUT); // définir pin lokola OUTPUT mpo na P2A
pinMode(EN12, OUTPUT); // définir pin lokola OUTPUT mpo na 1,2EN enable
}
Na boucle, moteur epesameli commande ya kopelusa na ba directions mibale na ba délais na kati. État ya moteur ekomami na moniteur ya série na kosalela Serial.println.
void loop() {
Serial.println("Kopelusa CW");
digitalWrite(EN12, HIGH); // Enable 1A mpe 2A
digitalWrite(P1A, HIGH); // kotinda signal HIGH na P1A
digitalWrite(P2A, LOW); // kotinda signal LOW na P2A
delay(3000); // moteur ezali kotambola mpo na secondes 3
digitalWrite(EN12, LOW); // Disable 1A mpe 2A
}
Extrait oyo elakisi ndenge ya kokamba direction ya libale ya moteur na kobongola ba niveaux ya logique oyo batindami na P1A mpe P2A. Moteur ezali kotambola mpo na secondes 3 liboso ya kotelema mpe kobongola direction.
Tala ndenge ba drivers ya demi-pont ya L293D basalelami:
Démonstration / Nini Okoki Kozela
Ntango setup esili mpe code ekomi kotomelama, osengeli komona moteur ezali kopota na direction moko na secondes 3, kozonga na secondes 2, mpe na sima kopota na direction oyo ekeseni na secondes 3 mosusu. Eteni ya moteur ekomama na écran ya serial monitor, mpo na kondima ba actions (na vidéo na 12:00).
Makambo ya mbeba oyo ezali mingi ezali kotalela ete tension ya malamu epesamela moteur mpe kotalela ete ba connexions ya moteur ezali malamu. Soki moteur eyambi te, tala lisusu ba câbles mpe ba connexions ya courant.
Ba Timestamps ya Vidéo
- 00:00 - Libandeli
- 02:30 - Ndimbola ya ba câbles
- 05:00 - Botali ya code
- 10:00 - Emoniseli ya bokonzi ya moteur
++
/*
* This is the Arduino code L293 DC motor driver (Advanced).
Using this code you can control a motor to rotate in both directions: clockwise (CW)
and counter-clockwise (CCW).
* *
// Written by Ahmad S. for Robojax.com on
// February 25, 2018 at 18:30 in Ajax, Ontario, Canada
* Permission granted to share this code given that this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational purposes only.
*
* watch L293 video for details https://youtu.be/jAmDliHcTJ0
* Code is available at http://robojax.com/learn/arduino
*
*/
// DC motor 1 control
#define P1A 2 // define pin 2 as for P1A
#define P2A 7 // define pin 7 as for P2A
#define EN12 8 // define pin 8 as for 1,2EN enable
// DC motor 2 control
#define P3A 10 // define pin 10 as for P3A
#define P4A 13 // define pin 13 as for P4A
#define EN34 9 // define pin 9 as for EN3 and EN4 enable
/*
* Permission granted to share this code given that this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational purposes only.
*
*/
void setup() {
// L293 Motor Control Code by Robojax.com 2018025
Serial.begin(9600);// setup Serial Monitor to display information
pinMode(P1A, OUTPUT);// define pin as OUTPUT for P1A
pinMode(P2A, OUTPUT);// define pin as OUTPUT for P2A
pinMode(EN12, OUTPUT);// define pin as OUTPUT for 1,2EN
pinMode(P3A, OUTPUT);// define pin as OUTPUT for P3A
pinMode(P4A, OUTPUT);// define pin as OUTPUT for P4A
pinMode(EN34, OUTPUT);// define pin as OUTPUT for 3,4EN
// L293 Motor Control Code by Robojax.com 2018025
}
void loop() {
// L293 Motor Control Code by Robojax.com 2018025
Serial.println("Rotating CW");
digitalWrite(EN12 ,HIGH);// Enable 1A and 2A
digitalWrite(P1A,HIGH);// send + or HIGH signal to P1A
digitalWrite(P2A,LOW);// send - or LOW signal to P2A
delay(3000);// motor runs for 3 seconds
digitalWrite(EN12 ,LOW);// Disable 1A and 2A
delay(2000);// motor stop for 3 seconds
Serial.println("Motor Stopped");
// L293 Motor Control Code by Robojax.com 2018025
// now changing the direction of rotation of motor
Serial.println("Rotating CCW");
digitalWrite(EN12 ,HIGH);// Enable 1A and 2A
digitalWrite(P1A,LOW);// send + or HIGH signal to P1A
digitalWrite(P2A,HIGH);// send - or LOW signal to P2A
delay(3000);// motor runs for 3 seconds
digitalWrite(EN12 ,LOW);// Disable 1A and 2A
delay(2000);// motor stop for 3 seconds
Serial.println("Motor Stopped");
Serial.println("=========== Loop done");
delay(500);
// L293 Motor Control Code by Robojax.com 2018025
}
/*
* This is the Arduino code L293 DC motor driver (Advanced).
Using this code you can control a motor to rotate in both directions: clockwise (CW)
and counter-clockwise (CCW).
* *
// Written by Ahmad S. for Robojax.com on
// February 25, 2018 at 18:30 in Ajax, Ontario, Canada
* Permission granted to share this code given that this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational purposes only.
*
* Watch L293 video for details: https://youtu.be/jAmDliHcTJ0
* Code is available at: http://robojax.com/learn/arduino
*
*/
// DC motor 1 control
#define P1A 2 // define pin 2 as for P1A
#define P2A 7 // define pin 7 as for P2A
#define EN12 8 // define pin 8 as for 1,2EN enable
// DC motor 2 control
#define P3A 10 // define pin 10 as for P3A
#define P4A 13 // define pin 13 as for P4A
#define EN34 9 // define pin 9 as for EN3 and EN4 enable
/*
* Permission granted to share this code given that this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational purposes only.
*
*/
void setup() {
// L293 Motor Contro Code by Robojax.com 2018025
Serial.begin(9600);// setup Serial Monitor to display information
pinMode(P1A, OUTPUT);// define pin as OUTPUT for P1A
pinMode(P2A, OUTPUT);// define pin as OUTPUT for P2A
pinMode(EN12, OUTPUT);// define pin as OUTPUT for 1,2EN
pinMode(P3A, OUTPUT);// define pin as OUTPUT for P3A
pinMode(P4A, OUTPUT);// define pin as OUTPUT for P4A
pinMode(EN34, OUTPUT);// define pin as OUTPUT for 3,4EN
// L293 Motor Contro Code by Robojax.com 2018025
}
void loop() {
if(value == 45){
rotateMA("CW",HIGH); // start motor in CW
}
delay(3000);
rotateMA("CW",LOW); // stop motor
delay(2000);
rotateMA("CCW",HIGH); // start motor in CCW
delay(3000);
rotateMA("CW",LOW); /// stop motor
delay(2000);
// L293 Motor Contro Code by Robojax.com 2018025
}// loop ends
/**
* function: rotateMA(String di,int action)
* Sends power to motor A
* di is a string and can be "CW" or "CCW"
* to use:
* rotateMA("CW",HIGH);// to rotate motor CW
* rotateMA("CCW",HIGH);// to rotate motor CCW
* to stop the motor:
* rotateMA("CW",LOW);// to stop motor
*/
void rotateMA(String di,int endis)
{
// L293 Motor Contro Code by Robojax.com 2018025
if(di =="CW"){
Serial.println(" Rotating CW");
digitalWrite(EN12 ,endis);// Enable 1A and 2A
digitalWrite(P1A,HIGH);// send + or HIGH signal to P1A
digitalWrite(P2A,LOW);// send - or LOW signal to P2A
}else{
// L293 Motor Contro Code by Robojax.com 2018025
// now changing the direction of rotation of motor
Serial.println(" Rotating CCW");
digitalWrite(EN12 ,endis);// Enable 1A and 2A
digitalWrite(P1A,LOW);// send + or HIGH signal to P1A
digitalWrite(P2A,HIGH);// send - or LOW signal to P2A
}
// L293 Motor Contro Code by Robojax.com 2018025
}//rotateMA ends here
Nko o na nki.
-
AmazonPurchase L293D motor driver ICamzn.to
-
AliExpressPurchase L293D motor driver IC from AliExpresss.click.aliexpress.com
Mokili na bisika
Pas encore de ressources.
Fichiers📁
Fiche technique (pdf)
-
robojax_L293D_motor_shield_manual.pdf
robojax_L293D_motor_shield_manual.pdf0.16 MB -
L293d datasheet
L293d_datasheet.pdf0.34 MB