Search Code

سبق 55-1: پش بٹنوں کا استعمال کرتے ہوئے ایک سنگل ڈی سی موٹر کو کنٹرول کرنا

سبق 55-1: پش بٹنوں کا استعمال کرتے ہوئے ایک سنگل ڈی سی موٹر کو کنٹرول کرنا

اس ٹیوٹوریل میں، ہم سیکھیں گے کہ L298N موٹر کنٹرولر ماجیول، پش بٹنز اور پوٹینشیومیٹر کا استعمال کرتے ہوئے ایک ڈی سی موٹر کو کیسے کنٹرول کیا جائے۔ بٹن دبانے سے، ہم موٹر کو گھڑی کی سمت یا مخالف گھڑی کی سمت گھما سکتے ہیں، نیز اسے روک سکتے ہیں اور پوٹینشیومیٹر کا استعمال کرتے ہوئے اس کی رفتار کو کنٹرول کر سکتے ہیں۔ یہ پروجیکٹ آرڈوینو پروجیکٹس میں موٹر کنٹرول کو سمجھنے کے لیے بہترین ہے اور ہارڈویئر انٹرفیسنگ کے ساتھ عملی تجربہ فراہم کرتا ہے۔ مزید وضاحت کے لیے، اس ٹیوٹوریل کے ساتھ موجود ویڈیو ضرور دیکھیں (ویڈیو میں 0:45 پر)۔

L298N Motor Controller Module
L298N موٹر کنٹرولر ماجیول

ہارڈویئر کی وضاحت

اس پروجیکٹ کا بنیادی جزو L298N موٹر کنٹرولر ہے، جو آپ کو ڈی سی موٹرز کی سمت اور رفتار کو کنٹرول کرنے کی اجازت دیتا ہے۔ یہ H-برج کنفیگریشن کا استعمال کرتے ہوئے کام کرتا ہے، جس سے موٹر دونوں سمتوں میں گھوم سکتی ہے۔ ماجیول کو 6 سے 35 وولٹ کے درمیان سپلائی وولٹیج درکار ہوتی ہے، جو اسے مختلف موٹر اقسام کے لیے موزوں بناتی ہے۔ مزید برآں، اس میں PWM (پلس وڈتھ ماڈیولیشن) کی صلاحیتیں ہیں، جو رفتار کنٹرول کی اجازت دیتی ہیں۔ ہم موٹر کی سمت کو کنٹرول کرنے اور اسے روکنے کے لیے پش بٹن بھی استعمال کریں گے۔ پوٹینشیومیٹر موٹر کی رفتار کو ایڈجسٹ کرنے میں مدد کرے گا۔ یہ اجزاء مل کر آپ کے آرڈوینو پروجیکٹس میں موٹر آپریشنز کو منظم کرنے کا ایک آسان لیکن مؤثر طریقہ فراہم کرتے ہیں۔

ڈیٹاشیٹ کی تفصیلات

صنعت کار STMicroelectronics
پارٹ نمبر L298N
لاجک/آئی او وولٹیج 5 V
سپلائی وولٹیج 6–35 V (VS)
آؤٹ پٹ کرنٹ (فی چینل) 2 A زیادہ سے زیادہ/چینل (abs. max)، 1 A عام مسلسل
پیک کرنٹ (فی چینل) 3 A
PWM فریکوئنسی رہنمائی 5 kHz
ان پٹ لاجک تھریشولڈز 0.8 V (کم)، 2.0 V (زیادہ)
وولٹیج ڈراپ / RDS(on) / سیچوریشن 2 V (عام)
تھرمل حدود 150 °C
پیکیج Multiwatt15
نوٹس / ویریئنٹس 2 موٹرز تک کنٹرول کر سکتا ہے
  • مسلسل آپریشن کے لیے مناسب ہیٹ سنکنگ کو یقینی بنائیں۔
  • زیادہ گرمی سے بچنے کے لیے رفتار کنٹرول کے لیے PWM پن استعمال کریں۔
  • موٹر ڈرائیور کی گراؤنڈ کو آرڈوینو کی گراؤنڈ سے جوڑیں۔
  • نقصان سے بچنے کے لیے سپلائی وولٹیج سے محتاط رہیں۔
  • مستحکم ریڈنگز کو یقینی بنانے کے لیے پش بٹنز کے لیے پل-اپ ریزسٹرز استعمال کریں۔
  • بیک پاورنگ مسائل سے بچنے کے لیے پروگرامنگ کے دوران پاور سپلائی منقطع کریں۔
Arduino wiring for L298N with pot 3push button to control 2 motors
Arduino wiring for L298N with pot 3push button to control 2 motors
Arduino wiring for L298N with pot 3push button to control single motor
Arduino wiring for L298N with pot 3push button to control single motor

وائرنگ ہدایات

Arduino wiring for L298N with pot 3push button to control single motor
L298N کے ساتھ آرڈوینو وائرنگ برائے پوٹ اور 3 پش بٹن کے ساتھ ایک موٹر کنٹرول

L298N موٹر کنٹرولر کو آرڈوینو کے ساتھ وائر کرنے کے لیے، بیٹری کے مثبت ٹرمینل کو L298N ماجیول کے VCC ٹرمینل سے اور منفی ٹرمینل کو GND سے جوڑ کر شروع کریں۔ L298N کے GND ٹرمینل کو بھی آرڈوینو کے GND سے جوڑیں۔ L298N سے 5V آؤٹ پٹ کو آرڈوینو کے 5V ان پٹ سے جوڑا جا سکتا ہے، لیکن تنازعات سے بچنے کے لیے صرف پروگرامنگ کے بعد۔ اگلا، موٹر کو L298N کے آؤٹ پٹ ٹرمینلز سے جوڑیں۔ موٹر کنٹرول کے لیے، ان پٹ پنوں کو اس طرح وائر کریں: IN1 کو آرڈوینو کے پن 2 سے، IN2 کو پن 4 سے، اور انیبل پن ENA کو پن 3 سے جوڑیں۔ پش بٹنز کے لیے، ہر بٹن کا ایک رخ GND سے جوڑیں، اور دوسرا رخ اس طرح: ڈائریکشن بٹن کو پن 8 سے، اسٹاپ بٹن کو پن 9 سے جوڑیں۔ آخر میں، پوٹینشیومیٹر کو جوڑیں: ایک رخ GND سے، دوسرا 5V سے، اور درمیانی پن کو آرڈوینو کے A0 سے۔

Arduino wiring for L298N with pot 3push button to control 2 motors
L298N کے ساتھ آرڈوینو وائرنگ برائے پوٹ اور 3 پش بٹن کے ساتھ 2 موٹرز کنٹرول

کوڈ مثالیں اور واک تھرو

درج ذیل کوڈ سنیپٹ موٹر کنٹرول کو انیشیالائز کرتا ہے اور پنوں کو سیٹ اپ کرتا ہے:


#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

تصاویر

L298N Motor Controller Module
L298N Motor Controller MOdule
Arduino wiring for L298N with pot 3push button to control single motor
Arduino wiring for L298N with pot 3push button to control single motor
Arduino wiring for L298N with pot 3push button to control 2 motors
Arduino wiring for L298N with pot 3push button to control 2 motors
485-Lesson 55: Controlling a DC motor using push buttons
زبان: C++
/*
 * 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
486-Lesson 55: Controlling 2 DC Motors with push buttons with L298N
زبان: C++
/*
 * 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

آپ کو جن چیزوں کی ضرورت ہو سکتی ہے

فائلیں📁

دیگر فائلیں