Controlling rc car with bluetooth

For my performance assignment, I needed to build a car controlled via phone, I built the car but it doesn't work.
Parts I used:
-Arduino Uno
-4 pieces of 6V 250 RPM motor and wheel set.
-HC05 Arduino Bluetooth module.
-L298 DC and stepper motor driver module.
-9v battery.
I tested all the motors with battery and connected them together in parallel.
I connected the 9V battery to the L298 and removed additional cables from there and connected the middle one to the GND pin on the Arduino and the right one to the VIN pin.
I connected the IN1 IN2 IN3 IN4 pins on L298 to the 6th pin, 10th pin, 5th pin and 9th pin on the Arduino respectively.
I connected the VCC GND TXD RXD pins on the HC05 to the 5V pin, GND pin, RX pin (i.e. pin 0) and TX pin (i.e. pin 1) on the Arduino, respectively.
While uploading the code, I removed the RX and tx pins and uploaded the code, then plugged them back in and used 2 applications in order to test the vehicle, their names are:
-Arduino Car (produced by One day of code)
-Bluetooth RC Controller (produced by Andi.Co)
But as a result, the car did not start. I tested the engines and they are working, I connect to the applications but the car does not start.
(sorry for the spelling mistakes, my native language is not english)


  const int motorA1  = 5;  
  const int motorA2  = 6;  
  const int motorB1  = 10; 
  const int motorB2  = 9;  


  int i=0; 
  int j=0; 
  int state; 
  int vSpeed=255; 

void setup() {
    pinMode(motorA1, OUTPUT);
    pinMode(motorA2, OUTPUT);
    pinMode(motorB1, OUTPUT);
    pinMode(motorB2, OUTPUT);    
    Serial.begin(9600);
}
 
void loop() {
 
//     if(digitalRead(BTState)==LOW) { state='S'; }

    if(Serial.available() > 0){     
      state = Serial.read();   
    }
  
    if (state == '0'){
      vSpeed=0;}
    else if (state == '1'){
      vSpeed=100;}
    else if (state == '2'){
      vSpeed=180;}
    else if (state == '3'){
      vSpeed=200;}
    else if (state == '4'){
      vSpeed=255;}
     

    if (state == 'F') {
      analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0);
        analogWrite(motorB1, vSpeed);      analogWrite(motorB2, 0); 
    }
    else if (state == 'G') {
      analogWrite(motorA1,vSpeed ); analogWrite(motorA2, 0);  
        analogWrite(motorB1, 100);    analogWrite(motorB2, 0); 
    }
    else if (state == 'I') {
        analogWrite(motorA1, 100); analogWrite(motorA2, 0); 
        analogWrite(motorB1, vSpeed);      analogWrite(motorB2, 0); 
    }
    else if (state == 'B') {
      analogWrite(motorA1, 0);   analogWrite(motorA2, vSpeed); 
        analogWrite(motorB1, 0);   analogWrite(motorB2, vSpeed); 
    }
    else if (state == 'H') {
      analogWrite(motorA1, 0);   analogWrite(motorA2, 100); 
        analogWrite(motorB1, 0); analogWrite(motorB2, vSpeed); 
    }
    else if (state == 'J') {
      analogWrite(motorA1, 0);   analogWrite(motorA2, vSpeed); 
        analogWrite(motorB1, 0);   analogWrite(motorB2, 100); 
    }
    else if (state == 'L') {
      analogWrite(motorA1, vSpeed);   analogWrite(motorA2, 150); 
        analogWrite(motorB1, 0); analogWrite(motorB2, 0); 
    }
    else if (state == 'R') {
      analogWrite(motorA1, 0);   analogWrite(motorA2, 0); 
        analogWrite(motorB1, vSpeed);   analogWrite(motorB2, 150);     
    }
    else if (state == 'S'){
        analogWrite(motorA1, 0);  analogWrite(motorA2, 0); 
        analogWrite(motorB1, 0);  analogWrite(motorB2, 0);
    }  
}

You have made it impossible to debug your code because you cannot use the serial monitor to display messages showing the variables and progress of your code. Good luck.

When I try to upload the code without removing those pins, it gives an error, so there is nothing I can do.

No. In this country that is called "painting yourself into a corner". Use an appropriate Arduino for this project.

Try using this code, and tell me any errors it shows(if it shows).I tried to keep the code as same as yours.

#include <SoftwareSerial.h> // Include the SoftwareSerial library to communicate with HC-05

const int motorA1 = 5;  
const int motorA2 = 6;  
const int motorB1 = 10; 
const int motorB2 = 9;  

SoftwareSerial BTSerial(2, 3); // RX, TX pins for HC-05

int state = 'S'; // Initialize state variable
int vSpeed = 255; 

void setup() {
    pinMode(motorA1, OUTPUT);
    pinMode(motorA2, OUTPUT);
    pinMode(motorB1, OUTPUT);
    pinMode(motorB2, OUTPUT);    
    Serial.begin(9600);
    BTSerial.begin(9600); // Start serial communication with HC-05
}
 
void loop() {
    if (BTSerial.available() > 0) {     
        state = BTSerial.read(); // Read data from Bluetooth module  
    }
  
    if (state == '0') {
        vSpeed = 0;
    } else if (state == '1') {
        vSpeed = 100;
    } else if (state == '2') {
        vSpeed = 180;
    } else if (state == '3') {
        vSpeed = 200;
    } else if (state == '4') {
        vSpeed = 255;
    }
     
    if (state == 'F') {
        analogWrite(motorA1, vSpeed);
        analogWrite(motorA2, 0);
        analogWrite(motorB1, vSpeed);
        analogWrite(motorB2, 0); 
    } else if (state == 'G') {
        analogWrite(motorA1, vSpeed);
        analogWrite(motorA2, 0);  
        analogWrite(motorB1, 100);
        analogWrite(motorB2, 0); 
    } else if (state == 'I') {
        analogWrite(motorA1, 100);
        analogWrite(motorA2, 0); 
        analogWrite(motorB1, vSpeed);
        analogWrite(motorB2, 0); 
    } else if (state == 'B') {
        analogWrite(motorA1, 0);
        analogWrite(motorA2, vSpeed); 
        analogWrite(motorB1, 0);
        analogWrite(motorB2, vSpeed); 
    } else if (state == 'H') {
        analogWrite(motorA1, 0);
        analogWrite(motorA2, 100); 
        analogWrite(motorB1, 0);
        analogWrite(motorB2, vSpeed); 
    } else if (state == 'J') {
        analogWrite(motorA1, 0);
        analogWrite(motorA2, vSpeed); 
        analogWrite(motorB1, 0);
        analogWrite(motorB2, 100); 
    } else if (state == 'L') {
        analogWrite(motorA1, vSpeed);
        analogWrite(motorA2, 150); 
        analogWrite(motorB1, 0);
        analogWrite(motorB2, 0); 
    } else if (state == 'R') {
        analogWrite(motorA1, 0);
        analogWrite(motorA2, 0); 
        analogWrite(motorB1, vSpeed);
        analogWrite(motorB2, 150);     
    } else if (state == 'S') {
        analogWrite(motorA1, 0);
        analogWrite(motorA2, 0); 
        analogWrite(motorB1, 0);
        analogWrite(motorB2, 0);
    }
}

Thank you for your help, but there is no error. It was as I used in the previous code. When the RX and TX pins are connected, I get the same error (exit status 1) while loading the code. Apart from that, there is nothing else. I think the problem is not related to the code.

https://support.arduino.cc/hc/en-us/articles/6554914611228-Compilation-error-exit-status-1 . Maybe it is the app that you are using that is causing the problem

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