Some of you may know me already because of my previous post regarding my L298N motor driver. Now, I would like to ask for a help to determine what's the main problem. When I try to rotate the motors with through arduino before, it runs smoothly. (bluetooth controller). Til the time that the L298N motor driver exploded (in my theory, connection of battery wire causes it to explode). Now, I bought another L298N motor driver and the problem is that when I try to control it, the motor is not rotating. Here are some of my atttempts to figure out the problem but cant find it:
a) Connected the wirings of EN1 to IN1/IN2 and the motor rotates. Same goes to EN2 to IN3/IN4.. Works very fine (it rotates, PS: Not connected to arduino yet)
b) Uses Serial monitor to check if the text is being transmitted (works fine).
The problem is
a) After pinning the EN1/2,IN1/2/3/4 arduino digital pins and try to test it controlling, it doesn't works.
I do believe that the codes are not the problem here since I used the same pin slots and code for the first and second trials. (In short, I only changed the motor driver and wired it the as before where it works fine.)
My theory:
a) L298N is defective. (motor 1 rotates sometimes strangely even if without commands while it is pinned to arduino. the sequence is for every 1 sec i guess it rotates like 1 rev.)
b) Arduino has been affected by the explosion of L298N before.
c) Arduino's digital pins are doomed
int motorLpin1=3;
int motorLpin2=4;
int motorRpin1=5;
int motorRpin2=6;
int motorLpwm=7;
int motorRpwm=8;
int motorSpeed=125;
int turn=50;
void setup() {
Serial.begin(9600);
Serial.flush();
pinMode(motorLpin1,OUTPUT);
pinMode(motorLpin2,OUTPUT);
pinMode(motorRpin1,OUTPUT);
pinMode(motorRpin2,OUTPUT);
pinMode(motorLpwm,OUTPUT);
pinMode(motorRpwm,OUTPUT);
}
void loop() {
String input="";
while(Serial.available()){
input+=(char)Serial.read();
delay(5);
}
if(input=="Stop"){
stp();
}
else if(input=="Up"){
fwd();
}
else if(input=="Down"){
rev();
}
else if(input.indexOf("left")>-1){
lft();
}
else if(input.indexOf("Right")>-1){
rght();
}
else if(input!=""){
motorSpeed=input.toInt();
}
}
void fwd(){
analogWrite(motorLpwm,motorSpeed);
analogWrite(motorRpwm,motorSpeed);
digitalWrite(motorLpin1,1);
digitalWrite(motorLpin2,0);
digitalWrite(motorRpin1,1);
digitalWrite(motorRpin2,0);
}
void rev(){
analogWrite(motorLpwm,motorSpeed);
analogWrite(motorRpwm,motorSpeed);
digitalWrite(motorLpin1,0);
digitalWrite(motorLpin2,1);
digitalWrite(motorRpin1,0);
digitalWrite(motorRpin2,1);
}
void lft(){
analogWrite(motorLpwm,motorSpeed-turn);
analogWrite(motorRpwm,motorSpeed+turn);
digitalWrite(motorLpin1,0);
digitalWrite(motorLpin2,1);
digitalWrite(motorRpin1,1);
digitalWrite(motorRpin2,0);
}
void rght(){
analogWrite(motorLpwm,motorSpeed+turn);
analogWrite(motorRpwm,motorSpeed-turn);
digitalWrite(motorLpin1,1);
digitalWrite(motorLpin2,0);
digitalWrite(motorRpin1,0);
digitalWrite(motorRpin2,1);
}
void stp(){
analogWrite(motorLpwm,0);
analogWrite(motorRpwm,0);
digitalWrite(motorLpin1,1);
digitalWrite(motorLpin2,1);
digitalWrite(motorRpin1,1);
digitalWrite(motorRpin2,1);
}
Using 4x battery instead of 7. It's 18650 battery 3.7v