Hello,
I made a 4WD car using the L298N and 4 engines.
The problem is if the water 4 motor moves forward or reverse, the motors work step by step, as if "STEP" motor. But if I move 2 motors forward or backward, there is no problem, it works normally.
No good asking without schematic and sketch.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX | TX
int command ;
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
Serial.println("You're connected via Bluetooth");
pinMode(13,OUTPUT); //left motors forward
pinMode(12,OUTPUT); //left motors reverse
pinMode(11,OUTPUT); //right motors forward
pinMode(10,OUTPUT); //right motors reverse
}
void loop() {
if (mySerial.available())
{
command=(mySerial.read());
if (command=='F')
{
Serial.println("Forward");
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
}
else if (command=='B')
{
Serial.println("Reverse");
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
digitalWrite(10,HIGH);
}
else if (command=='L')
{
Serial.println("Left");
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
}
else if (command=='R')
{
Serial.println("Right");
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
}
else if (command=='S')
{
Serial.println("Stop");
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
}
delay(30);
}
}
i would suggest observing the direction that each wheel moves when all the motor are driven forward.
are they all wired appropriately to move the vehicle forward?
Yes, the cables are connected correctly. It's like a stepper motor, step by step all the way forward. How do I upload a video?
a typical motor controller (e.g. L298) might have a direction pin and an enable pin driven with a PWM signal to control speed.
looks like you have one OUTPUT pin controlling each motor and your 'S' commands sets them all LOW to stop the vehicles.
what exactly are these 4 pins doing? should each motor be controlled by a direction and enable pin?
I sent the schematic.
These pins control as 2 left motors and 2 right motors.
pinMode(13,OUTPUT); //left motors forward
pinMode(12,OUTPUT); //left motors reverse
pinMode(11,OUTPUT); //right motors forward
pinMode(10,OUTPUT); //right motors reverse
Motors connected in parallel
so what are your 4 arduino pins, 10, 11, 12, 13, connected to?
pinMode(13,OUTPUT); //left motors forward in2
pinMode(12,OUTPUT); //left motors reverse in1
pinMode(11,OUTPUT); //right motors forward in3
pinMode(10,OUTPUT); //right motors reverse in4
according to the diagram, in1 and in2 are not separate pins. pin5 is IN1&IN2. are you using a different L298 board?
which pins on the L298 board are your pins 12 & 13 connected to?
IN2 and IN1
do you see that in the diagram i posted that there are no separate pins labeled IN1 & IN2?
do you understand that i don't know which L298 board you're using and how it it connected?
With 2 motors in parallel, does it take more current than than max current?
(In other words, is your auto protection system kicking in? Or is the power supply insufficient?)
Did you check serial monitor for repeated startup of Arduino?
A voltage dip may cause a reset...
Are you using an Arduino UNO or Nano or Mega or Leonardo or Micro? If so you can't use pins 0 and 1 for both Serial and SoftwareSerial.