Hello.
I have a problem with my own project.
The project is a car that moves with two DC motors, L298n motor driver, two infrared sensors, and 1.5v x4 battery, and an Arduino Uno.
The problem is that when I tried each motor separately, the wheel moved, but when I tried them together, it did not work.
Please Help .
int IRR=A0;
int IRL=A1;
int ENA=5;
int IN1=6;
int IN2=7;
int ENB=3;
int IN3=2;
int IN4=4;
void setup() {
pinMode(ENA,OUTPUT);
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(ENB,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);
pinMode(IRR,INPUT);
pinMode(IRL,INPUT);
analogWrite(ENB,150);
analogWrite(ENA,150);
delay(1000);
}
void loop() {
if((digitalRead(IRR)==0)&&(digitalRead(IRL)==0)){
forword();
}
if((digitalRead(IRR)==1)&&(digitalRead(IRL)==0)){
turnRight();
}
if((digitalRead(IRR)==0)&&(digitalRead(IRL)==1)){
turnLeft();
}
if((digitalRead(IRR)==1)&&(digitalRead(IRL)==1)){
Stop();
}
}
void forword(){
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}
void turnRight(){
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}
void turnLeft(){
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
}
void Stop(){
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}
Starting with:
"The recommended range for the VIN pin on the Arduino Uno is 7–12 volts. The VIN pin is the input voltage to the Arduino board when it's using an external power source, as opposed to the 5 volts from the USB connection or other regulated power source".
You are supplying about 6.0 volts. Next, the L298 while nice as sliced bread in its day is not great today simply because of loss. Your motors will not see even close to 6.0 volts.
That's before even looking at your code. Additionally you really don't want your motors powered by the same supply as your uC (Arduino).
That is because the motors do not have enough power (volts in this case). You need to understand that the L298 drops about 3 volts before passing to the motor so a 6V battery will wind up giving the motor 3V. I highly recommend you get a replacement for the L298 that uses MOSFETs as an output. You would lose about 0.1 Volt with one of those.
I am new to robotics, so I did not know that the motors require a higher voltage than this.
Please tell me how much they need so I can replace the batteries
The motor shoud have a data sheet that tells rateted motor power votage.
If you pick a driver that willl handle rated voltage and stall current, you should have no ttouble. Remember, the drivr must briefly supply stall current evevry tme the motor stsrts.
Pololu (Pololu - Brushed DC Motor Drivers (among other vendors*) has a good selection of modern MOSFET output drivers that will perform circles around those old drivers.
I have no affiliation with Pololu except old customer. Their quality is worth the extra money.
It is not the voltage it is the current. Voltage is basically fixed if the source is adequate but the greater the load the more current is required. Motors draw many times there running current when starting. I have seen from 3 to about 15, it depends on the motor, and its load.