Wa Koodu

Lilo L298N Motor Driver lati Ṣakoso Motor Stepper Ona-4

Lilo L298N Motor Driver lati Ṣakoso Motor Stepper Ona-4

Nínú ẹ̀kọ́ yìí, a óò ṣàwárí bí a ṣe lè ṣàkóso mótò onígbese 4-wire ní lílo L298N motor driver pẹ̀lú Arduino. L298N jẹ́ driver H-bridge méjì tí ó wúlò tí ó jẹ́ kí a lè ṣàkóso ìtọ́sọ́nà àti ìyára mótò onígbese dáradára. Ní ìparí ìtọ́sọ́nà yìí, ìwọ yóò ní ètò tí ó ṣiṣẹ́ tí ó lè yí mótò onígbese padà ní àwọn ìtọ́sọ́nà méjèèjì àti ṣàkóso ìyára rẹ̀ ní lílo potentiometer.

L298N motor driver (yellow connector)

Láti ràn ọ́ lọ́wọ́ láti lóye ìlànà náà dáradára, mo dámọ̀ràn kí o wo fídíò tí ó somọ́, tí ó pèsè ìfihàn ojú tí ó wúlò nípa ìsopọ̀ àti kódù (nínú fídíò ní 01:30).

Ohun èlò tí a ṣàlàyé

L298N motor driver jẹ́ ètò tí a ṣe láti ṣàkóso mótò nípa gbígba ọ̀nà fún ọ wá láti wakọ̀ wọn ní ìtọ́sọ́nà iwájú àti ẹ̀yìn. Ó ń lo ìtòlẹ́ H-bridge, tí ó túmọ̀ sí pé ó lè yí polarity ti foltiège tí a fi sí mótò padà, nípa bẹ́ẹ̀ yí ìtọ́sọ́nà rẹ̀ padà. Driver yìí lè gba foltiège ipese tí ó tó 46V àti current tí ó ń lọ nígbà gbogbo ti 2A fún ikanni kọ̀ọ̀kan, tí ó mú un dára fún ọ̀pọ̀lọpọ̀ àwọn ohun èlò.

Nínú ètò wa, a óò lo àwọn pin ìṣàkóso mẹ́rin láti ṣàkóso mótò onígbese. Àwọn pin pàtàkì ni ENA àti ENB, tí a gbọ́dọ̀ ṣètò sí HIGH (5V) láti mú driver ṣiṣẹ́. Àwọn pin IN1, IN2, IN3, àti IN4 yóò ṣàkóso àwọn ipo yíyí mótò, tí ó jẹ́ kí ó lè ṣe igbese ní ìtọ́sọ́nà tí a fẹ́.

Àwọn àlàyé Datasheet

OlùṣeSTMicroelectronics
Nọ́mbà apáL298N
Foltiège Logic/IO5 V
Foltiège ipese5–46 V (VS)
Current ìjàde (fún ikanni)2 A max/ikanni (nígbà gbogbo)
Current tí ó ga jùlọ (fún ikanni)3 A max
Ìtọ́sọ́nà ìgbohùnsáfẹ́fẹ́ PWM1 kHz sí 20 kHz
Àwọn ìpele ìṣàkóso input0.8 V (low), 2.0 V (high)
Ìdínku foltiège / RDS(on) / saturation1.5 V max
Àwọn ìwọ̀n ooru150 °C max
ÀpótíDIP-15
Àwọn àkíyèsí / àwọn oríṣiríṣiTún wà ní àwọn ẹ̀yà pẹ̀lẹ́bẹ̀ (L298P)

  • Rí i dájú pé ENA àti ENB ti sopọ̀ sí 5V fún iṣẹ́ tí ó tọ́.
  • Lo ìmú oorun tí ó tọ́ fún àwọn ohun èlò tí ń lo current púpọ̀ láti yẹra fún gbígbóná janjan.
  • Mú ilẹ̀ tí ó wọ́pọ̀ wà láàrin Arduino àti motor driver.
  • Ṣọ́ra nípa polarity ìsopọ̀ láti yẹra fún bí bàjẹ́ mótò tàbí driver.
  • Fi àwọn capacitors decoupling sí ẹ̀gbẹ́ àwọn pin agbára láti ṣèjà àríwọ́.
  • Ṣàtúnṣe ìgbohùnsáfẹ́fẹ́ PWM ní ìbámu pẹ̀lú àwọn ìpàtàkì mótò fún iṣẹ́ tí ó dára jùlọ.

Àwọn Ìtọ́sọ́nà Ìsopọ̀

L298N motor driver (yellow connector)
L298N motor driver (yellow connector)

Láti so L298N motor driver pọ̀ mọ́ Arduino àti mótò onígbese, bẹ̀rẹ̀ nípa sísopọ̀ ipese agbára. So pin VIN lórí L298N pọ̀ mọ́ orísun agbára 12V rẹ. Ní ìgbà tí ó tẹ̀lé, so pin GND lórí L298N pọ̀ mọ́ ilẹ̀ orísun agbára rẹ àti pẹ̀lú ilẹ̀ Arduino.

Nísinsin yìí, fún àwọn pin ìṣàkóso, so ENA pọ̀ mọ́ pin 2 lórí Arduino àti ENB pọ̀ mọ́ pin 3. Ní ìgbà tí ó tẹ̀lé, so IN1 pọ̀ mọ́ pin 8, IN2 pọ̀ mọ́ pin 9, IN3 pọ̀ mọ́ pin 10, àti IN4 pọ̀ mọ́ pin 11 lórí Arduino. Ní ìparí, so àwọn okun mótò onígbese pọ̀ mọ́ àwọn ibi ìjàde L298N. Rí i dájú pé àwọn okun méjì méjì láti mótò ti sopọ̀ dáradára sí àwọn ìjàde.

Àwọn Àpẹẹrẹ Kódù & Ìtọ́sọ́nà

Nínú kódù, a kọ́kọ́ fi Stepper.h library sí inú láti rọrùn ṣàkóso mótò onígbese. A ṣàlàyé nọ́mbà àpapọ̀ àwọn igbese fún yíyí kíkún, tí ó ṣe pàtàkì fún ìṣísẹ̀ pípé. Àwọn idanimọ̀ pàtàkì nínú kódù pẹ̀lú stepsPerRevolution, tí ó ṣètò nọ́mbà àwọn igbese tí a nílò fún yíyí kíkún, àti myStepper, tí ó bẹ̀rẹ̀ ohun elo stepper pẹ̀lú àwọn pin tí a yàn.

const int stepsPerRevolution = 200;  // yí èyí padà láti bá nọ́mbà àwọn igbese fún yíyí kíkún mu
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); // bẹ̀rẹ̀ stepper library

Àkọsílẹ̀ yìí bẹ̀rẹ̀ mótò onígbese pẹ̀lú àwọn pin tí ó tọ́. Nínú iṣẹ́ setup(), a ṣètò ìyára mótò àti mú driver ṣiṣẹ́ nípa ṣíṣètò àwọn pin 2 àti 3 sí HIGH.

void setup() {
  myStepper.setSpeed(300); // ṣètò ìyára ní 60 rpm
  pinMode(2,OUTPUT); // fún EN1
  digitalWrite(2,HIGH); // mú EN1 ṣiṣẹ́
  pinMode(3,OUTPUT); // fún EN2
  digitalWrite(3,HIGH); // mú EN2 ṣiṣẹ́
}

Nínú iṣẹ́ loop(), mótò ń ṣe igbese yíyí kíkún ní àwọn ìtọ́sọ́nà aago àti lòdì sí aago pẹ̀lú ìdúró ní àárín. Èyí jẹ́ kí o lè ṣàkíyèsí iṣẹ́ mótò.

void loop() {
  myStepper.step(stepsPerRevolution); // ṣe igbese yíyí kíkún ní ìtọ́sọ́nà kan
  delay(500); // dúró fún idaji aaya
  myStepper.step(-stepsPerRevolution); // ṣe igbese yíyí kíkún ní ìtọ́sọ́nà mìíràn
  delay(500); // dúró fún idaji aaya
}

Àkọsílẹ̀ yìí ṣàfihàn bí a ṣe lè ṣàkóso mótò láti yí padà ní àwọn ìtọ́sọ́nà méjèèjì. Kódù kíkún náà wá ní ìsàlẹ̀ àpilẹ̀kọ fún ìtọ́kasi rẹ.

Ìfihàn / Ohun tí o lè retí

Ni gbogbo ohun ti a ti so pọ daradara ati pe koodu ti gbe soke, o yẹ ki o ri motor stepper ti n yi kikun kan ni ọna kan, ti o tẹle pẹlu kikun kikun ni ọna idakeji. Ni afikun, ti o ba fi potentiometer kun fun iṣakoso iyara, ṣiṣatunṣe rẹ yoo yi iyara iyipo ti motor pada. Ṣọra fun lọwọlọwọ motor; bi o ṣe n pọ si iyara, motor le fa lọwọlọwọ diẹ sii, eyi ti o le yorisi gbigbona pupọ ti ko ba ṣakoso daradara (ninu fidio ni 09:45).

Ti motor ko ba yi pada bi a ti ṣe reti, ṣayẹwo awọn okun lati rii daju pe gbogbo awọn asopọ wa ni aabo ati pe o tọ. Tun rii daju pe folti ipese agbara ṣe deede fun motor stepper rẹ.

Awọn Akoko Fidio

  • 00:00 - Ifihan
  • 01:30 - Alaye Asopọ
  • 05:00 - Akopọ Koodu
  • 09:45 - Ifihan Iṣakoso Motor

Aworan

L298N motor driver (yellow connector)
L298N motor driver (yellow connector)
L298N motor driver (yellow connector)
L298N motor driver (yellow connector)
L298N motor driver (yellow connector)
L298N motor driver (yellow connector)
Nema17_stpper_motor-1
Nema17_stpper_motor-1
Nema17_stpper_motor-2
Nema17_stpper_motor-2
94-Code for One Revolution
Ede: C++
/*
 Stepper Motor Control - one revolution

 This program drives a unipolar or bipolar stepper motor.
 The motor is attached to digital pins 8 - 11 of the Arduino.

 The motor should revolve one revolution in one direction, then
 one revolution in the other direction.


 Created 11 Mar. 2007
 Modified 30 Nov. 2009
 by Tom Igoe

 Modified by Ahmad S. for Robojax.com
 on May 19, 2018 at 19:31, in Ajax, Ontario, Canada

 */

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(300);
  // initialize the serial port:
  Serial.begin(9600);
  // L298N for Robojax.com 
  pinMode(2,OUTPUT);// for EN1
  digitalWrite(2,HIGH);// enable EN1
  pinMode(3,OUTPUT);// for EN1
  digitalWrite(3,HIGH); // enable EN2
}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

// L298N for Robojax.com 
  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}
95-Code for rotating a stepper motor one step at a time
Ede: C++
/*
 Stepper Motor Control - one step at a time

 This program drives a unipolar or bipolar stepper motor.
 The motor is attached to digital pins 8 - 11 of the Arduino.

 The motor will step one step at a time, very slowly. You can use this to
 test that you've got the four wires of your stepper wired to the correct
 pins. If wired correctly, all steps should be in the same direction.

 Use this also to count the number of steps per revolution of your motor,
 if you don't know it. Then plug that number into the oneRevolution
 example to see if you got it right.

 Created 30 Nov. 2009
 by Tom Igoe

 Modified by Ahmad S. for Robojax.com
 on May 19, 2018 at 19:31, in Ajax, Ontario, Canada
 */

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

int stepCount = 0;         // number of steps the motor has taken

void setup() {
  // initialize the serial port:
  Serial.begin(9600);

  // L298N for Robojax.com 
  pinMode(2,OUTPUT);// for EN1
  digitalWrite(2,HIGH);// enable EN1
  pinMode(3,OUTPUT);// for EN1
  digitalWrite(3,HIGH); // enable EN2
}  


void loop() {
  // step one step:
    // L298N for Robojax.com 
  myStepper.step(-1);
  Serial.print("steps:");
  Serial.println(stepCount);
  stepCount++;
  delay(200);
}

Orisun & itọkasi

Ko si awọn orisun sibẹsibẹ.

Fáìlìs📁

Fọọmu data (pdf)