Arduino bluetooth car probelm

Hello! This is my second post on this forum, so I wanted to thank you for the help for the previous problem. This time I'm creating a bluetooth car with hc-05 model and a motor shield l293D. I think that my code is fine because functions are working when I type through the serial monitor. However, it's not working with a bluetooth. HC-05 is successfully conected but when I send the commands, nothing happens. I tried HC-05 with a LED and it was working, but with motors it doesn't work. I also tried diffrent apps, but it's the same. Does anyone knows what could be wrong? Here's the code:

#include <AFMotor.h>
int g;
AF_DCMotor motora(1);
AF_DCMotor motorb(2);
AF_DCMotor motorc(3);
AF_DCMotor motord(4);
void setup()
{
  Serial.begin(9600);
  motora.setSpeed(70);
  motorb.setSpeed(70);
  motorc.setSpeed(70);
  motord.setSpeed(70);
}
void loop() {
  if(Serial.available()>0){
    g = Serial.read();
    if(g=='0'){
      motora.run(FORWARD);
      motorb.run(FORWARD);
      motorc.run(FORWARD);
      motord.run(FORWARD);
      }
     else if(g=='1'){
      motora.run(BACKWARD);
      motorb.run(BACKWARD);
      motorc.run(BACKWARD);
      motord.run(BACKWARD);      
      }
      else  if(g=='2'){
      motora.run(RELEASE);
      motorb.run(RELEASE);
      motorc.run(RELEASE);
      motord.run(RELEASE);
        
        }
    }
}

Everything you note would lead me question the power.
How is everything powered?
Can you provide a hand drawn schematic of how everything is connected?

Have You verified the HC-05 link to work using just a simple HC-05 example code?

USB is connected to arduino, while 9V battery to the motor shield

HC-05 is connected to the motor shield

I mean yes, I turned 2 LEDs on and off via bluetooth.

Is that a small rectangular 9V smoke alarm battery (PP3)? That battery is totally unsuited for powering motors. It does not have the current capacity. Coupled with the 2 to 4 volt drop from the L293 it is no wonder that the motors do not work right.

I would not use the main serial port (Serial) to communicate with the HC05. I would use a spare hardware port, if available, or a software serial port and save the Serial port for program upload, monitoring program flow and variable values and debugging.

Yes it is (PP3). So, battery can be the problem? It was working well before connecting with the bluetooth (with serial monitor and just motors going forward or backward). Okay then, which power supply do you suggest insted of this PP3?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.