A
Arduino•4y ago
MaderDash

How to drive a motor useing l298

@Grogu (Rey)
50 Replies
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
here is a detailed post on the 298 with proper wireing options. https://supperslash.wixsite.com/arduinobasics/l298n
MaderDash
MaderDashOP•4y ago
NOTE 9v batterys are not good for motors.
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
Toph
Toph•4y ago
may want to check if the button has pullups
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
Toph
Toph•4y ago
!pullup
Arduino
Arduino•4y ago
What does pullup (or pulldown) mean, and how do I use it?
Pins used as INPUT should not be left unconnected (floating).
This can lead to undesired behavior. If input pins are connected to digital sensors then the sensor itself usually keeps the pin either HIGH or LOW.
Pins used with switches (pushbuttons or other) should use a resistor to 'pull' the pin HIGH or LOW.
If the pin is connected to Vcc through a resistor it is said to be 'pulled up', if the pin goes to ground through a resistor it is said to be 'pulled down'. When a resistor is used this way the input is held at either Vcc or ground when the switch is not closed so that it is never 'floating'. Pins that are pulled down are normally LOW and go HIGH when the switch (wired to Vcc) is closed. Pins that are pulled up are normally HIGH and go LOW when the switch (wired to ground) is closed. (The resistor, often 10K, allows only a small current to flow from Vcc to ground when the switch is closed, if the pin was tied directly to a power rail closing the switch would short out the power supply!)
Many chips include internal resistors so that an external resistor doesn't need to be added to your circuit.
On the ATmega328P chips used on many Arduino boards you can pull up the pin by using pinMode(pin, INPUT_PULLUP). If the pin is declared this way it is normally HIGH and all that is needed is a switch wired from the pin to ground. When the switch is closed the pin will go LOW. The example below shows pin 2 setup this way.
From An unknown user
Arduino Bot • Submit bugs on GitHub!
MaderDash
MaderDashOP•4y ago
@Tophgreat point but RN the motor is not moving at all, so I figured there would be a good place to start, I know the code had an error in it but we are waiting on a wirediagram first.
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
Toph
Toph•4y ago
yup... seeing how everything is connected will allow MaderDash to help
MaderDash
MaderDashOP•4y ago
conect your motor/s like this
No description
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
ok let me know when you have that done
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
if you just follow that example I gave there should be everything you need there. even some basic test code?
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
use the B example for the powering
No description
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
correct, but for now you shouldent and just power the board by USB, because the battery may not be able to provide enough power currently so stick with wireing B till it passes the tests please?
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
correct.
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
after we get things working better, then we can just add that wire. PLUSS REMEMBER::: You never want to supply anything to the 5v pin and the USB. you only conect ONE AT A TIME or you can take out your pc's USB port.
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
Looking good now unhook the bat, so it does not go dead
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
last wireing to do is:
MaderDash
MaderDashOP•4y ago
No description
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
If you want to use others, let me know what pins you want to use and I will change code for you.'
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
there is 4 pins so please let me know what you want to use @Grogu (Rey)
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
13,9 is for motor A and 12,10 for motor B?
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
dubble check that and I will code
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
is the pin mapping correct? 13,9 motorA 12,10 motorB ?
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
ok
/*Date: 07-08-2021
By: Maderdash
This is just a test code to test if the driver is running correctly.
We are not useing the EN pins on the controller.
Be sure the jumpers are conected to the EN pins. Or apply 5v to both pins.

*/

int motor1pin1 = 13;
int motor1pin2 = 9;

int motor2pin1 = 12;
int motor2pin2 = 10;

void setup() {
// put your setup code here, to run once:
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(motor2pin1, OUTPUT);
pinMode(motor2pin2, OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
analogWrite(motor1pin1, 255);
analogWrite(motor1pin2, 0);

analogWrite(motor2pin1, 255);
analogWrite(motor2pin2, 0);
Serial.println("direction A is turing now.");
delay(1000);

analogWrite(motor1pin1, 0);
analogWrite(motor1pin2, 255);

analogWrite(motor2pin1, 0);
analogWrite(motor2pin2, 255);
Serial.println("direction A is turing now.");
delay(1000);
}
/*Date: 07-08-2021
By: Maderdash
This is just a test code to test if the driver is running correctly.
We are not useing the EN pins on the controller.
Be sure the jumpers are conected to the EN pins. Or apply 5v to both pins.

*/

int motor1pin1 = 13;
int motor1pin2 = 9;

int motor2pin1 = 12;
int motor2pin2 = 10;

void setup() {
// put your setup code here, to run once:
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(motor2pin1, OUTPUT);
pinMode(motor2pin2, OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
analogWrite(motor1pin1, 255);
analogWrite(motor1pin2, 0);

analogWrite(motor2pin1, 255);
analogWrite(motor2pin2, 0);
Serial.println("direction A is turing now.");
delay(1000);

analogWrite(motor1pin1, 0);
analogWrite(motor1pin2, 255);

analogWrite(motor2pin1, 0);
analogWrite(motor2pin2, 255);
Serial.println("direction A is turing now.");
delay(1000);
}
Test code here upload this code and see if the motors spin after reconecting the 9v
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
keep it conected.
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
GREAT. NOW lets see what you can understand about the code. Power down the project as you cdont want the battery to die.
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
it will as its pushing all the power through this is why we did not conect the arduino to that board also it would make it get even hotter. 😮 Ok so what do you understand about the code I sent you?
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
MaderDash
MaderDashOP•4y ago
got it lets work ont hat part. lets go to coding help and you can mark this thread as solved it would be great.
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?