Hi.
I have a problem in my project which involves controlling a car remotely by HC-05 Bluetooth module.
the components:
-Arduino Uno
-l298n
-2 DC motors
-HC-05 -
-12V battery
power supply:
12 V (battery) -> 12 (l298n)
and -> Vin(Arduino)
Gnd (battery) -> Gnd (l298n)
and -> Gnd(Arduino)
5V (Arduino) -> Vcc (HC-05)
Gnd (Arduino) -> Gnd (HC-05)
When sending the code the Bluetooth LED, it lights up, but the two motors do not work.
I have already tested both motors and they work perfectly, so there are no problems with either motor.
Please help me as I don't know where the error is.
#include <SoftwareSerial.h>
int ER=5;
int R1=6;
int R2=7;
int EL=3;
int L1=2;
int L2=4;
int bluetoothTx= 10;
int bluetoothRx= 11;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup() {
pinMode(ER,OUTPUT);
pinMode(R1,OUTPUT);
pinMode(R2,OUTPUT);
pinMode(EL,OUTPUT);
pinMode(L1,OUTPUT);
pinMode(L2,OUTPUT);
bluetooth.begin(9600);
Serial.begin(9600);
}
void loop() {
if(bluetooth.available()){
char command = bluetooth.read();
Serial.println(command);
if(command=='F'){
digitalWrite(R1,LOW);
digitalWrite(R2,HIGH);
digitalWrite(L1,LOW);
digitalWrite(L2,HIGH);
analogWrite(ER,255);
analogWrite(EL,255);
}
else if(command=='B'){
digitalWrite(R1,HIGH);
digitalWrite(R2,LOW);
digitalWrite(L1,HIGH);
digitalWrite(L2,LOW);
analogWrite(ER,255);
analogWrite(EL,255);
}
else if(command=='R'){
digitalWrite(R1,HIGH);
digitalWrite(R2,LOW);
digitalWrite(L1,LOW);
digitalWrite(L2,HIGH);
analogWrite(ER,255);
analogWrite(EL,255);
}
else if(command=='L'){
digitalWrite(R1,LOW);
digitalWrite(R2,HIGH);
digitalWrite(L1,HIGH);
digitalWrite(L2,LOW);
analogWrite(ER,255);
analogWrite(EL,255);
}
else if(command=='S'){
digitalWrite(R1,LOW);
digitalWrite(R2,LOW);
digitalWrite(L1,LOW);
digitalWrite(L2,LOW);
analogWrite(ER,0);
analogWrite(EL,0);
}
}
}



