Hi guys I'm completely new to all this stuff I'm about to explain so apologies in advance if there's something I'm doing wrong.
So, for this project I'm working on I need to move a robot carrying a load from point A to point B. To do that I'm testing out a code to run two DC motors at the same time. I read that I need a motor shield to run two DC motors using an arduino so i got a L298N Dual Motor Driver (I attached the data sheet, also wesite where i got it from https://www.jaycar.com.au/arduino-compatible-stepper-motor-controller-module/p/XC4492) and two DC motors from pololu (Pololu - 131:1 Metal Gearmotor 37Dx73L mm 12V with 64 CPR Encoder (Spur Pinion)).
So i wrote a test code that will speed up the motors in one direction and slow it down in the other direction. But the problem was only the motor connected to motor B port was running and it was jerking and stopping so i disconnected it from the battery. So I thought it was my code and decided to add a bigger delay between the two for loops but it still had the same problem. Idiot me thought why not try and leave it like that for a few seconds and see what happens. So I did and that's why I heard a spark. I disconnected the shield from the battery as soon as i heard that spark but after a while i started to smell something burning. I thought it was the motor but after testing out only one motor connected to port A both motors work fine. Then i connected it to portB and the motors won't turn.
Can anyone explain what happened? Thanks!
//Define variables here
#define ENA 6 //PWM input 1
#define ENB 5 //PWM input 2
#define IN1 4 //motor a forward
#define IN2 7 //motor a backward
#define IN3 3 //motor b forward
#define IN4 2 //motor b backward
void motorArun(int mspeed, bool forward, bool backward) {
analogWrite (ENB, mspeed);
digitalWrite (IN1,forward);
digitalWrite (IN2, backward);
delay(1);
}
void motorBrun(int mspeed, bool forward, bool backward) {
analogWrite (ENB, mspeed);
digitalWrite (IN3,forward);
digitalWrite (IN4, backward);
delay(1);
}
void setup() {
// put your setup code here, to run once:
pinMode (ENA, OUTPUT); //Motor enable pin
pinMode (ENB, OUTPUT);
pinMode (IN1, OUTPUT);
pinMode (IN2, OUTPUT);
pinMode (IN3, OUTPUT);
pinMode (IN4, OUTPUT);
}
void loop() {
//speed up the motors
for (int i = 0; i < 255; i++) {
motorArun(i, HIGH, LOW);
motorBrun(i, HIGH, LOW);
}
delay(1);
//slow down the motors in the other direction
for (int i = 255; i > 0; i--) {
motorArun(i, LOW, HIGH);
motorBrun(i, LOW, HIGH);
}
}
dataSheetMain.pdf (803 KB)