This might be a duplicate topic but I haven't found the solution yet.
I'm making a 2 wheeled Bluetooth RC car using Arduino Uno, L298N driver, HC05 Bluetooth Module, 4 X AA Battery.
Wiring is similar to the above image, the difference only in the pin L298N assignment.
Bluetooth goes to Arduino TX, RX, 5V, and Ground. Arduino V in input was connected to L298N 5V and Ground.
The circuit was fine for a few days. Now it's only working when Arduino is connected to my laptop through the serial cable. The only thing I can think of is when I change the name of my BT module (since I did it a few hours before it broke, but I successfully control the car after I changed the name).
Any insight on why this is happening?
In case anyone wondering, I use a modified code (I add more if command) that I find from the internet.
Your image looks incomplete - how do you power the Arduino?
Can you provide a circuit diagram with labeld connections on all modules?
Sorry, I took this image from google. I mentioned it above that the image is the reference I use.
I'll type the label
L298N 12V and HND from the battery
L298N <---> Arduino
5V --> Vin
Gnd --> Gnd
EN1 --> 10
EN2 --> 9
In 1 --> 7
In 2 --> 6
In 3 --> 5
In 4 --> 4
HC05 <--> Arduino
Tx --> Rx
Rx --> Tx
VCC --> 5V
Gnd --> Gnd
You should use software serial to hookup the HC-05 to pins D2 and D3 instead of RX and TX.
Could you post your code?
What's this 5V supply? If it works with an USB connection then your power supply may be too weak.
My guess is that the Arduino isn´t receiving enough power. Arduino Vin passes through the board voltage regulator (which has a voltage loss). If you´re using 5V incoming from L298N, you can connect it to +5V.
EDIT: I agree with @DrDiettrich
I agree too
@DrDiettrich L298N can convert 12V to 5v using its regulator I think. It can supply the Arduino (It even works for a few days).
@Brazilino I also thought that it might doesn't get enough current, that's why I try using a brand new 4 x AA battery, but it doesn't work. HC05 does turn on when I connect HC05 vcc to Arduino Vin , but the motor doesn't run.
Try using a L7805 voltage regulator for your 5v power supply. That way everything is getting all the power it needs.
This looks no good...
@kgray9 also has a good point.
Not together with a BT module.
This is something like a toy module so everything is in a set. Seems like it should be fine but idk why mine only lasts a few days. Any insight on why it only lasts for a short time before going weird? And which part is broken? I swapped the HC05 and the arduino board and in both scenarios, it couldn't connect. So I suspect it's the L298N. But I don't understand what kind of error is this.
Most probably the batteries are drained to a degree where the BT module stops working.
Sorry for the late reply. I tried changing the L298N but the same thing happened.
@DrDiettrich I tried using completely new batteries and it still can't turn on the HC05. Wouldn't be able to function at all if it's only because of the batteries.
I also borrowers a similar car from a friend with the same wiring configuration and his car is fine. The only difference is that I use the PWM for L298N and he doesn't + car might be from a different supplier.
What batteries are these? 1.5V AA, or AAA? Did you try a regulated +5V supply? Or a regulated +3.3V supply?
The status LED:
- Blink once in 2 sec: Module has entered Command Mode
- Repeated Blinking: Waiting for connection in Data Mode
- Blink twice in 1 sec: Connection successful in Data Mode
Is the status LED doing any of those? Or is it not lighting up at all?
Well, it´s time to take a look at your code, if you don´t mind posting it. Remember to use code tags to do it ( the icon while editing your text).
You can take a look at your friend´s car wiring to see how it goes.
Another nice thing would be to show some pics of your project (the real connections, not an example).
Ok, here is the code. In the second trial, I use softwareserial to change the Tx Rx pin.
I'll upload another image later. (A photo of the actual car or a fritzing diagram?)
//#include <SoftwareSerial.h>
//SoftwareSerial BT(11, 12); //HC06-TX Pin 11, HC06-RX to Arduino Pin 12
//int LED = 13; //Use whatever pins you want
int speedS = 10;
int speedT = 10;
char t;
void setup() {
//BT.begin(9600); //Baudrate 9600 , Choose your own baudrate (Uncomment if use manual bluetooth)
Serial.begin(9600);
//pinMode(LED, OUTPUT);
pinMode(4, OUTPUT); //
pinMode(5, OUTPUT); //
pinMode(6, OUTPUT); //
pinMode(7, OUTPUT); //
pinMode(9, OUTPUT); //PWM
pinMode(10, OUTPUT); //PWM
}
void loop() {
// Use this one if you set up the bluetooth pin yourself
/*
if (BT.available()) {
t = BT.read();
BT.println(t);
Serial.println(t);
}
*/
// Use this one if bluetooth goes to Arduino Tx Rx
if (Serial.available()) {
t = Serial.read();
//Serial.println(t);
}
int pwmT = map(speedT, 0, 10, 0, 255); // Convert 1-10 to analog value
int pwmS = map(speedS, 0, 10, 0, 255); // Convert 1-10 to analog value
if (t == '1') { //move forward(all motors rotate in forward direction)
analogWrite(9, pwmS);
analogWrite(10, pwmS);
digitalWrite(4, HIGH);
digitalWrite(6, HIGH);
Serial.print("Straight, Speed : ");
Serial.println(speedS);
}
else if (t == '2') { //move reverse (all motors rotate in reverse direction)
analogWrite(9, pwmS);
analogWrite(10, pwmS);
digitalWrite(5, HIGH);
digitalWrite(7, HIGH);
Serial.print("Straight, Speed : ");
Serial.println(speedS);
}
else if (t == '3') { //turn right (left side motors rotate in forward direction, right side motors doesn't rotate)
//analogWrite(9, pwmT);
analogWrite(10, pwmT);
digitalWrite(6, HIGH);
Serial.print("Right, Speed : ");
Serial.println(speedT);
}
else if (t == '4') { //turn left (right side motors rotate in forward direction, left side motors doesn't rotate)
analogWrite(9, pwmT);
//analogWrite(10, pwmT);
digitalWrite(4, HIGH);
Serial.print("Left, Speed : ");
Serial.println(speedT);
}
else if (t == '5') {
if (speedS < 10) {
speedS += 1;
}
else if (speedS == 10) {
speedS = speedS;
}
Serial.println((String)"Speed : "+speedS);
}
else if (t == '6') {
if (speedS > 0) {
speedS -= 1;
}
else if (speedS == 0) {
speedS == speedS;
}
Serial.println((String)"Speed : "+speedS);
}
else if (t == '7') {
if (speedT < 10) {
speedT += 1;
}
else if (speedT == 10) {
speedT = speedT;
}
Serial.println((String)"Speed : "+speedT);
}
else if (t == '8') {
if (speedT > 0) {
speedT -= 1;
}
else if (speedT == 0) {
speedT == speedT;
}
Serial.println((String)"Speed : "+speedT);
}
else if (t == '0') { //STOP (all motors stop)
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
Serial.println("Stop");
}
delay(100);
}
That´s also ok, but when using HC-06 at Uno Rx/Tx you should disconnect HC-06 before uploading the program to the board.
When you´re setting pins 4,6 to HIGH, pins 5,7 might be set to low and vice-versa.
A photo (or photos) of the actual car allowing people to see the wiring connections. Fritzing diagrams are fancy for pasting in school works, but they don´t bring important information that even a hand draw schematics can provide
At first, I feared that any of the modules is broken, so I changed every module (I didn't change the motor or batteries and it still doesn't run, so probably the supply is the problem.
Here are the pictures of how I wire the car. This is the second one since I disassemble the first car (it still retains the problem). I will probably try my HC05 module on my friend's car ASAP to make sure that my HC05 is fine.
Thanks for the pics!
At a first glance, I can see no problem between your wiring and your code. Looks like there´s a missing wire from the upper motor to the L298N (maybe behind the other wire, and I can´t see it).
Have you seen this? Your code should be corrected.
Vin pin needs 7-12 V to operate correctly. So, giving him 5V is not enough. Try connecting HC-05 VCC and the L298N 5V to Arduino 5V together, instead of using Vin pin.
This is also a good thing to do!
It seems that it is indeed a power supply problem. 6V batteries cannot power both arduino and HC05. I changed 4XAA Batteries to a 9V battery, 9V to both Arduino Vin and the L298N 12V, L298N 5V to HC05 VCC. Everything turned on now, but sometimes it disconnects after 1-3 commands or it keeps connected but the motor isn't moving or both. Is it because it doesn't have enough current?
Thanks for the help guys.