પાઠ 55-1: પુશ બટનોનો ઉપયોગ કરીને એક જ ડીસી મોટરને નિયંત્રિત કરવી
આ ટ્યુટોરિયલમાં, આપણે L298N મોટર કંટ્રોલર મોડ્યુલ, પુશ બટનો અને પોટેન્શિયોમીટરનો ઉપયોગ કરીને એક જ DC મોટરને કેવી રીતે નિયંત્રિત કરવી તે શીખીશું. બટનો દબાવીને, આપણે મોટરને ઘડિયાળની દિશામાં અથવા ઘડિયાળની વિરુદ્ધ દિશામાં ફેરવી શકીએ છીએ, તેમજ તેને રોકી શકીએ છીએ અને પોટેન્શિયોમીટરનો ઉપયોગ કરીને તેની ગતિ નિયંત્રિત કરી શકીએ છીએ. આ પ્રોજેક્ટ Arduino પ્રોજેક્ટ્સમાં મોટર નિયંત્રણ સમજવા માટે ઉત્તમ છે અને હાર્ડવેર ઇન્ટરફેસિંગ સાથે વ્યવહારુ અનુભવ પ્રદાન કરે છે. વધુ સ્પષ્ટતા માટે, આ ટ્યુટોરિયલ સાથેના વિડિયોને ચોક્કસપણે જુઓ (વિડિયોમાં 0:45 પર).
હાર્ડવેર સમજાવ્યું
આ પ્રોજેક્ટમાં પ્રાથમિક ઘટક L298N મોટર કંટ્રોલર છે, જે તમને DC મોટર્સની દિશા અને ગતિ નિયંત્રિત કરવાની મંજૂરી આપે છે. તે H-બ્રિજ રૂપરેખાંકનનો ઉપયોગ કરીને કાર્ય કરે છે, જે મોટરને બંને દિશામાં ફેરવવા સક્ષમ બનાવે છે. મોડ્યુલને 6 થી 35 વોલ્ટની સપ્લાય વોલ્ટેજની જરૂર પડે છે, જે તેને વિવિધ મોટર પ્રકારો માટે બહુમુખી બનાવે છે. વધુમાં, તેમાં PWM (પલ્સ વિડ્થ મોડ્યુલેશન) ક્ષમતાઓ છે, જે ગતિ નિયંત્રણ માટે પરવાનગી આપે છે. આપણે મોટરની દિશા નિયંત્રિત કરવા અને તેને રોકવા માટે પુશ બટનોનો પણ ઉપયોગ કરીશું. પોટેન્શિયોમીટર મોટરની ગતિ સમાયોજિત કરવામાં મદદ કરશે. આ ઘટકો તમારા Arduino પ્રોજેક્ટ્સમાં મોટર કામગીરીનું સંચાલન કરવાની સરળ છતાં અસરકારક રીત પ્રદાન કરવા માટે સાથે મળીને કાર્ય કરે છે.
ડેટાશીટ વિગતો
| ઉત્પાદક | STMicroelectronics |
|---|---|
| ભાગ નંબર | L298N |
| લોજિક/IO વોલ્ટેજ | 5 V |
| સપ્લાય વોલ્ટેજ | 6–35 V (VS) |
| આઉટપુટ કરંટ (પ્રતિ ચેનલ) | 2 A મહત્તમ/ચેનલ (એબ્સ. મહત્તમ), 1 A ટાઇપ. સતત |
| પીક કરંટ (પ્રતિ ચેનલ) | 3 A |
| PWM આવર્તન માર્ગદર્શન | 5 kHz |
| ઇનપુટ લોજિક થ્રેશોલ્ડ | 0.8 V (નીચું), 2.0 V (ઊંચું) |
| વોલ્ટેજ ડ્રોપ / RDS(on) / સેચ્યુરેશન | 2 V (ટાઇપ.) |
| થર્મલ મર્યાદાઓ | 150 °C |
| પેકેજ | મલ્ટીવોટ15 |
| નોંધો / વેરિઅન્ટ્સ | 2 મોટર્સ સુધી નિયંત્રિત કરી શકે છે |
- સતત કામગીરી માટે યોગ્ય હીટ સિંકિંગની ખાતરી કરો.
- ઓવરહિટિંગ ટાળવા માટે ગતિ નિયંત્રણ માટે PWM પિનનો ઉપયોગ કરો.
- મોટર ડ્રાઇવરની ગ્રાઉન્ડને Arduino ગ્રાઉન્ડ સાથે જોડો.
- નુકસાન અટકાવવા માટે સપ્લાય વોલ્ટેજથી સાવચેત રહો.
- સ્થિર રીડિંગ્સની ખાતરી કરવા માટે પુશ બટનો માટે પુલ-અપ રેઝિસ્ટરનો ઉપયોગ કરો.
- બેક-પાવરિંગ સમસ્યાઓ ટાળવા માટે પ્રોગ્રામિંગ કરતી વખતે પાવર સપ્લાય ડિસ્કનેક્ટ કરો.


વાયરિંગ સૂચનાઓ
L298N મોટર કંટ્રોલરને Arduino સાથે વાયર કરવા માટે, બેટરીના પોઝિટિવ ટર્મિનલને L298N મોડ્યુલ પરના VCC ટર્મિનલ સાથે અને નેગેટિવ ટર્મિનલને GND સાથે જોડીને શરૂ કરો. L298N ના GND ટર્મિનલને પણ Arduino ના GND સાથે જોડો. L298N માંથી 5V આઉટપુટને Arduino ના 5V ઇનપુટ સાથે જોડી શકાય છે, પરંતુ સંઘર્ષ ટાળવા માટે માત્ર પ્રોગ્રામિંગ પછી. આગળ, મોટરને L298N ના આઉટપુટ ટર્મિનલ સાથે જોડો. મોટર નિયંત્રણ માટે, ઇનપુટ પિનને નીચે મુજબ વાયર કરો: IN1 ને Arduino પર પિન 2 સાથે, IN2 ને પિન 4 સાથે અને એનેબલ પિન ENA ને પિન 3 સાથે જોડો. પુશ બટનો માટે, દરેક બટનની એક બાજુ GND સાથે વાયર કરો, અને બીજી બાજુ નીચે મુજબ: દિશા બટનને પિન 8 સાથે, સ્ટોપ બટનને પિન 9 સાથે જોડો. છેલ્લે, પોટેન્શિયોમીટરને જોડો: એક બાજુ GND સાથે, બીજી 5V સાથે, અને મધ્યમ પિનને Arduino પર A0 સાથે.
કોડ ઉદાહરણો અને વોકથ્રુ
નીચેનો કોડ સ્નિપેટ મોટર નિયંત્રણ શરૂ કરે છે અને પિન સેટ કરે છે:
#include
#define IN1 2
#define IN2 4
#define ENA 3
const int motor1PushButtonDirection = 8;
const int motor1PushButtonStop = 9;
void setup() {
Serial.begin(115200);
motor.begin();
pinMode(motor1PushButtonDirection, INPUT_PULLUP);
pinMode(motor1PushButtonStop, INPUT_PULLUP);
}
આ ભાગમાં, આપણે L298N મોટર નિયંત્રણ માટે જરૂરી લાઇબ્રેરી શામેલ કરીએ છીએ અને મોટર અને પુશ બટનો માટે પિન વ્યાખ્યાયિત કરીએ છીએ. `setup()` ફંક્શન સીરિયલ કમ્યુનિકેશન શરૂ કરે છે અને બટન પિનને પુલ-અપ રેઝિસ્ટર સાથે ઇનપુટ તરીકે સેટ કરે છે. આગળ, આપણે બટનોની સ્થિતિ તપાસીએ છીએ અને લૂપમાં મોટરને નિયંત્રિત કરીએ છીએ:
void loop() {
updateState1();
if(motor1StopState == HIGH) {
motor.brake(motor1);
} else {
motor.rotate(motor1, motor1Speed, motor1Direction);
}
delay(pushButtonDelayTime);
}
અહીં, `loop()` ફંક્શન સતત પુશ બટનોની સ્થિતિ તપાસે છે. જો સ્ટોપ બટન દબાવવામાં આવે છે, તો મોટર બ્રેક થશે; અન્યથા, તે નિર્દિષ્ટ ગતિ અને દિશામાં ફરશે. `updateState1()` ફંક્શન બટન સ્થિતિઓ વાંચે છે અને મોટર દિશા અપડેટ કરે છે:
void updateState1() {
if(digitalRead(motor1PushButtonDirection) == LOW) {
motor1Direction = (motor1Direction == CW) ? CCW : CW;
Serial.println("દિશા બદલાઈ");
}
if(digitalRead(motor1PushButtonStop) == LOW) {
motor1StopState = 1 - motor1StopState; // શરૂ/બંધ ટૉગલ કરો
}
}
આ ફંક્શન જ્યારે દિશા બટન દબાવવામાં આવે ત્યારે મોટરની દિશા ટૉગલ કરે છે અને જ્યારે સ્ટોપ બટન દબાવવામાં આવે ત્યારે સ્ટોપ સ્થિતિ ટૉગલ કરે છે. સંપૂર્ણ કોડ માટે, કૃપા કરીને નોંધ લો કે તે લેખની નીચે લોડ થાય છે.
પ્રદર્શન / શું અપેક્ષા રાખવી
જ્યારે તમે પ્રોગ્રામ ચલાવો છો, ત્યારે તમે પુશ બટનો અને પોટેન્શિયોમીટરનો ઉપયોગ કરીને મોટરની દિશા અને ઝડપ નિયંત્રિત કરી શકશો. દિશા બટન દબાવવાથી ઘડિયાળની દિશામાં અને ઘડિયાળની વિરુદ્ધ દિશામાં પરિભ્રમણ વચ્ચે ટૉગલ થશે, જ્યારે સ્ટોપ બટન મોટર શરૂ અથવા બંધ કરશે (વિડિઓમાં 12:30 પર). પોટેન્શિયોમીટર સેટિંગ્સથી સાવચેત રહો; જો ખૂબ ઓછું સેટ કરવામાં આવે, તો મોટર શરૂ થઈ શકે નહીં.
પ્રકરણો
- પરિચય – 0:00
- હાર્ડવેર ઝાંખી – 1:30
- વાયરિંગ સૂચનાઓ – 3:45
- કોડ વૉકથ્રુ – 6:00
- પ્રદર્શન – 12:00
/*
* Lesson 55: Controlling DC Motors with 2 push buttons with L298N
* Library Example for L298N Module to control with 2 push buttons
* One Push button is used for CW/CCW
* and one push button is used to stop the motor
Download and resource page https://robojax.com/RJT506
Watch video for full details of this code: https://youtu.be/diS_WkUdU-8
*
* Written by Ahmad Shamshiri on October 20, 2019 at 14:58
* in Ajax, Ontario, Canada. www.robojax.com
*
*
*
* Get this code and other Arduino codes from Robojax.com
If you found this tutorial helpful, please support me so I can continue creating
content like this.
or make a donation using PayPal http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been downloaded from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <Robojax_L298N_DC_motor.h>
// motor 1 settings
#define IN1 2
#define IN2 4
#define ENA 3 // ~this pin must be PWM enabled pin
const int CCW = 2; // do not change
const int CW = 1; // do not change
#define motor1 1 // do not change
#define motor2 2 // do not change
const int pushButtonDelayTime =200;
//*** Push buttons for motor 1 started
int motor1Speed =60;// speed of motor 1 in % (60 means 60%)
const int motor1PushButtonDirection = 8;// push button for direction change
const int motor1PushButtonStop = 9;// push button for START/STOP
const int motor1Minimum =15;//30% is minimum for motor 1
// do not change below this line
int motor1Direction =CCW;//
int motor1StopState=HIGH;//Stope state of motor 1
//*** Push buttons for motor 1 started ended
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// use the line below for single motor
Robojax_L298N_DC_motor motor(IN1, IN2, ENA, true);
// use the line below for two motors
//Robojax_L298N_DC_motor motor(IN1, IN2, ENA, IN3, IN4, ENB, true);
void setup() {
Serial.begin(115200);
motor.begin();
//L298N DC Motor by Robojax.com
pinMode(motor1PushButtonDirection, INPUT_PULLUP);
pinMode(motor1PushButtonStop, INPUT_PULLUP);
}
void loop() {
updateState1();//read all push 1 buttons
if(motor1StopState ==HIGH)
{
motor.brake(motor1);
}else{
motor.rotate(motor1, motor1Speed, motor1Direction);
}
//motor.demo(1);
//motor.rotate(motor1, motor1Speed, CW);//run motor1 at 60% speed in CW direction
delay(pushButtonDelayTime);
}//
/*
*
* updateState1()
* @brief reads push buttons and updates values
* @param none
* @return no return
* Written by Ahmad Shamshiri for robojax.com
* on October 13, 2019 in Ajax, Ontario, Canada
*/
void updateState1()
{
if(digitalRead(motor1PushButtonDirection) ==LOW){
if(motor1Direction ==CW)
{
motor1Direction =CCW;//
Serial.println("*****Now CCW");
}else{
motor1Direction =CW;//
Serial.println("*****Now CW");
}
}
if(digitalRead(motor1PushButtonStop) ==LOW)
{
motor1StopState =1-motor1StopState;// toggle Star/stop
}
}//updateState end
/*
* Lesson 55: Controlling 2 DC Motors with push buttons with L298N
* Library Example for L298N Module to control with 2 push buttons
* One push button is used for CW/CCW
and one push button is used to stop the motor
* (this code is to control 2 motors). See the first code for a single motor
Download and resource page https://robojax.com/RJT506
Watch video for full details of this code: https://youtu.be/diS_WkUdU-8
*
*
* Written by Ahmad Shamshiri on October 20, 2019 at 14:58
* in Ajax, Ontario, Canada. www.robojax.com
*
*
*
* Get this code and other Arduino codes from Robojax.com
If you found this tutorial helpful, please support me so I can continue creating
content like this.
or make a donation using PayPal http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been downloaded from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <Robojax_L298N_DC_motor.h>
// motor 1 settings
#define IN1 2
#define IN2 4
#define ENA 3 // this pin must be PWM enabled pin
// motor 2 settings
#define IN3 7
#define IN4 6
#define ENB 5 // this pin must be PWM enabled pin
const int CCW = 2; // do not change
const int CW = 1; // do not change
#define motor1 1 // do not change
#define motor2 2 // do not change
const int pushButtonDelayTime =200;
//*** Push buttons for motor 1 started
int motor1Speed =60;// speed of motor 1 in % (60 means 60%)
const int motor1PushButtonDirection = 8;// push button for direction change
const int motor1PushButtonStop = 9;// push button for START/STOP
const int motor1Minimum =15;//30% is minimum for motor 1
// do not change below this line
int motor1Direction =CCW;//
int motor1StopState=HIGH;//Stop state of motor 1
//*** Push buttons for motor 1 started ended
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//*** Push buttons for motor 2 started
int motor2Speed =60;// speed of motor 2 in % (60 means 60%)
const int motor2PushButtonDirection = 10;// push button for direction change
const int motor2PushButtonStop = 11;// push button for START/STOP
const int motor2Minimum =15;//30% is minimum for motor 2
// do not change below this line
int motor2Direction =CCW;//
int motor2StopState=HIGH;//Stop state of motor 2
//*** Push buttons for motor 2 started ended
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// use the line below for 1 motor
//Robojax_L298N_DC_motor motor(IN1, IN2, ENA,true);
// use the line below for two motors
Robojax_L298N_DC_motor motor(IN1, IN2, ENA, IN3, IN4, ENB, true);
void setup() {
Serial.begin(115200);
motor.begin();
//L298N DC Motor by Robojax.com
// push buttons for motor 1
pinMode(motor1PushButtonDirection, INPUT_PULLUP);
pinMode(motor1PushButtonStop, INPUT_PULLUP);
//L298N DC Motor by Robojax.com
// push buttons for motor 2
pinMode(motor2PushButtonDirection, INPUT_PULLUP);
pinMode(motor2PushButtonStop, INPUT_PULLUP);
}
void loop() {
updateState1();//read push buttons value for motor 1
updateState2();//read push buttons value for motor 2
if(motor1StopState ==HIGH)
{
motor.brake(1);
}else{
motor.rotate(motor1, motor1Speed, motor1Direction);
}
if(motor2StopState ==HIGH)
{
motor.brake(2);
}else{
motor.rotate(motor2, motor2Speed, motor2Direction);
}
//motor.demo(1);
//motor.rotate(motor1, motor1Speed, CW);//run motor1 at 60% speed in CW direction
delay(pushButtonDelayTime);
}//
/*
*
* updateState1()
* @brief reads push buttons and updates values
* @param none
* @return no return
* Written by Ahmad Shamshiri for robojax.com
* on Oct 13, 2019 in Ajax, Ontario, Canada
*/
void updateState1()
{
if(digitalRead(motor1PushButtonDirection) ==LOW){
if(motor1Direction ==CW)
{
motor1Direction =CCW;//
Serial.println("***** Motor 1 Now CCW");
}else{
motor1Direction =CW;//
Serial.println("***** Motor 1 Now CW");
}
} //if for direction push button
if(digitalRead(motor1PushButtonStop) ==LOW)
{
motor1StopState =1-motor1StopState;// toggle Start/stop
}// if for start/stop push button
}//updateState1 end
/*
*
* updateState2()
* @brief reads push buttons and updates values
* @param none
* @return no return
* Written by Ahmad Shamshiri for robojax.com
* on Oct 13, 2019 in Ajax, Ontario, Canada
*/
void updateState2()
{
if(digitalRead(motor2PushButtonDirection) ==LOW){
if(motor2Direction ==CW)
{
motor2Direction =CCW;//
Serial.println("***** Motor 2 Now CCW");
}else{
motor2Direction =CW;//
Serial.println("***** Motor 2 Now CW");
}
} //if for direction push button
if(digitalRead(motor2PushButtonStop) ==LOW)
{
motor2StopState =1-motor2StopState;// toggle Start/stop
}// if for start/stop push button
}//updateState2 end
તમને જોઈતી વસ્તુઓ
-
eBay
-
AliExpressPurchase L298N Module from AliExpresss.click.aliexpress.com
-
AliExpressPurchase L298N Module from AliExpress (2)s.click.aliexpress.com
-
AliExpressPurchase L298N Module from eBayebay.us
સંસાધનો અને સંદર્ભો
-
બાહ્ય
-
બાહ્ય
-
આંતરિક
ફાઇલો📁
અન્ય ફાઇલો
-
Robojax L298N DC Motor Library
robojax_L298N-DC-Motor_library.zip0.10 MB