Tezlikni boshqarish pinlari:
Tezlikni boshqarish pinlari, ya’ni ENA va ENB mos ravishda A va B
motorlarini yoqish, о‘chirish va boshqarish tezligini yoqish uchun ishlatiladi. Ushbu
pinlarni HIGH tortib olish motorlarni aylantiradi, pastroq tortish ularni tо‘xtatishga
olib keladi. Biroq, PWM yordamida biz aslida motorlarning tezligini boshqarishimiz
mumkin.
79
1.10- rasm. Tezlikni boshqarish pinlari
Arduino UNO bilan ishlaydigan L293D Motor Driver:
Yendi biz IC ni Arduino ga bog‘lashni kо‘rib о‘tamiz. Elektr ta’minotini
motorlarga ulashdan boshlaymiz. Bu tajribamizda biz odatda ikkita g‘ildirakli
robotlarda uchraydigan DC Gearbox Motors ("TT" dvigatellari deb ham ataladi) dan
foydalanamiz. Ular 3 dan 9 V gacha bо‘lgan quvvatga ega. Shunday qilib, biz tashqi
9V quvvat manbaini Vcc2 piniga ulaymiz.
1.9-rasm. L293D Motor Driver IC-ni DC motors & Arduino bilan ulash
Keyinchalik, L293D ning mantiqiy sxemasi uchun 5 voltni yetkazib
berishimiz kerak. Vcc 1 pinini Arduino-da 5V chiqishiga ulanadi.
Endi L293D IC ning kirish va yoqish pinlari (ENA, IN1, IN2, IN3, IN4 va
ENB) oltita Arduino raqamli chiqish piniga (9, 8, 7, 5, 4 va 3) ulangan. Arduino
chiqish pinlari 9 va 3 ning ikkalasi ham PWM -ga ega ekanligini unutmang.
Nihoyat, bitta dvigatelni OUT1 va OUT2 ga, ikkinchisini esa OUT3 va
OUT4 ga ulanadi. Motorni ulanishlarini texnik jihatdan almashtirish mumkin, bu
yerda tо‘g‘ri yoki notо‘g‘ri yо‘l yо‘q. Sо‘ng, quyida kо‘rsatilgan rasmga о‘xshash
narsaga ega bо‘lishingiz kerak.
Arduino kodi - DC motorini boshqarish:
80
Quyidagi kod L293D dvigatel IC yordamida doimiy dvigatelning tezligi va
aylanish yо‘nalishini boshqarish bо‘yicha tо‘liq tushuncha beradi va amaliy
tajribalar va loyihalar uchun asos bо‘lib xizmat qilishi mumkin.
// Motor A connections
int
enA =
9
;
int
in1 =
8
;
int
in2 =
7
;
// Motor B connections
int
enB =
3
;
int
in3 =
5
;
int
in4 =
4
;
void
setup
() {
// Set all the motor control pins to outputs
pinMode
(enA, OUTPUT);
pinMode
(enB, OUTPUT);
pinMode
(in1, OUTPUT);
pinMode
(in2, OUTPUT);
pinMode
(in3, OUTPUT);
pinMode
(in4, OUTPUT);
// Turn off motors - Initial state
digitalWrite
(in1, LOW);
digitalWrite
(in2, LOW);
digitalWrite
(in3, LOW);
digitalWrite
(in4, LOW);
}
void
loop
() {
directionControl
();
delay
(
1000
);
speedControl
();
delay
(
1000
);
}
// This function lets you control spinning direction of motors
void
directionControl
() {
// Set motors to maximum speed
// For PWM maximum possible values are 0 to 255
analogWrite
(enA,
255
);
analogWrite
(enB,
255
);
81
// Turn on motor A & B
digitalWrite
(in1, HIGH);
digitalWrite
(in2, LOW);
digitalWrite
(in3, HIGH);
digitalWrite
(in4, LOW);
delay
(
2000
);
// Now change motor directions
digitalWrite
(in1, LOW);
digitalWrite
(in2, HIGH);
digitalWrite
(in3, LOW);
digitalWrite
(in4, HIGH);
delay
(
2000
);
// Turn off motors
digitalWrite
(in1, LOW);
digitalWrite
(in2, LOW);
digitalWrite
(in3, LOW);
digitalWrite
(in4, LOW);
}
// This function lets you control speed of the motors
void
speedControl
() {
// Turn on motors
digitalWrite
(in1, LOW);
digitalWrite
(in2, HIGH);
digitalWrite
(in3, LOW);
digitalWrite
(in4, HIGH);
// Accelerate from zero to maximum speed
for
(
int
i =
0
; i <
256
; i++) {
analogWrite
(enA, i);
analogWrite
(enB, i);
delay
(
20
);
}
// Decelerate from maximum speed to zero
for
(
int
i =
255
; i >=
0
; --i) {
analogWrite
(enA, i);
analogWrite
(enB, i);
delay
(
20
);
}
// Now turn off motors
digitalWrite
(in1, LOW);
digitalWrite
(in2, LOW);
|