Lesson 55: Controlling DC Motors with 2 push buttons with L298N | Arduino Step By Step Course

preview_player
Показать описание
In this lesson we learn how to control two DC motor using L298N motor driver and 2 push buttons. One push button is used to start or stop the motor and one push button is to toggle the direction of rotation between clockwise CW and counterclockwise CCW.

The best thank you for me is to not to skip ads and Subscribe 🔔 to my channel, like 👍 the video It is greatly appreciated. 🔔 😊.
I will reply to all Subscriber's 🔔 questions. So make sure to Subscribe.😊 .

*** Purchase Arduino Start Kit ***

**** Purchase L298N Motor Driver Module from ****

****** Purchase Authentic Arduino Uno from ****

Download Arduino code for this video:

Use Chapters from timeline or click on the time
00:00 Introduction
01:52 Wiring Explained
05:47 Code Explained (one motor)
13:49 Demonstration (one motor)
15:12 Demonstration (two motors)

Tutorial by Ahmad Shamshiri form Canada
****************************
****************************

Power Supply I use:

Get other projects code and learn Arduino
#robojax #robojaxArduinoCourse #robojax_

**** AFFILIATE PROGRAM ****
Рекомендации по теме
Комментарии
Автор

Hello Robojax, thanks for the videos. I am currently trying to make this circuit for single DC motor, I have made the same connections as you and my Arduino and L298N board are both powering up correctly. However, the motor does not start and the push buttons do not seem to be turning the motor on either. Do you know what I can do to fix this issue?
Thank you

AadamZafar
Автор

I have a doubt inorder to power a 6v DC motor do i need to provide power >6v or 6v along can power up the motor, is there any voltage drop in this driver ?

elowpiku
Автор

Hi, I'm very new in arduino uno coding. I was looking for your lesson 55 code that control motor with l298n. The code is very nice but it's a little bit to much for what i'm looking for. I Just need to control the motor cw start by 1 switch and stop with another switch and than, after stop, turn a LED on with a digital IO. Can you help me? I can read and understand some easy codes but my knoledge is too Light to write the code myself. Thanks

louisdecarufel
Автор

Thanks, awesome video!
Please, do you have some video or coding to apply these steps for ESP 32?
Thanks again @Robojax

samuelfernandez
Автор

motor one is working but the second motor is not, knowing that i changed the code and declared all the pins:
#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 direcion 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


//*** Push buttons for motor 2 started
int motor1Speed =60;// speed of motor 1 in % (60 means 60%)
const int motor2PushButtonDirection = 10;// push button for direcion change
const int motor2PushButtonStop = 11;// push button for START/STOP
const int motor2Minimum =15;//30% is minimum for motor 1
// do not change below this line
int motor2Direction =CCW;//
int motor2StopState=HIGH;//Stope state of motor 1
//*** Push buttons for motor 2 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);
//L298N DC Motor by Robojax.com
pinMode(motor2PushButtonDirection, INPUT_PULLUP);
pinMode(motor2PushButtonStop, 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);

updateState2();//read all push 1 buttons

if(motor2StopState ==HIGH)
{
motor.brake(motor2);
}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()
{

==LOW){
if(motor1Direction ==CW)
{
motor1Direction =CCW;//
CCW");
}else{
motor1Direction =CW;//
CC");
}

}



==LOW)
{
motor1StopState =1-motor1StopState;// toggle Star/stop
}
}//updateState end
void updateState2()
{

==LOW){
if(motor2Direction ==CW)
{
motor2Direction =CCW;//
CCW");
}else{
motor2Direction =CW;//
CC");
}

}
==LOW)
{
motor2StopState =1-motor2StopState;// toggle Star/stop
}
}//updateState end

jadalkhabbaz
visit shbcf.ru