I have been having trouble building a remote control car. Not exactly building it, as earlier the car was working, but after I left it for a few days, the motors just won't run at all, I tried changing the code and everything but still the issue isn't solved.
The following is the code I am using:
#include <SoftwareSerial.h>
#include <AFMotor.h>
SoftwareSerial BT(A4, A5); // RX, TX (same as before)
AF_DCMotor motor1(1); // Motor on M1
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
//AF_DCMotor motor4(4);
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
motor1.setSpeed(255); // Full speed (0–255)
motor2.setSpeed(255);
motor3.setSpeed(255);
//motor4.setSpeed(255);
motor1.run(RELEASE); // Motor off at start
motor2.run(RELEASE);
motor3.run(RELEASE);
//motor4.run(RELEASE);
Serial.println("Bluetooth motor ready.");
Serial.println(Serial1.available());
}
void loop() {
// Serial.println("Entered loop");
if (Serial1.available()) {
char cmd = Serial1.read();
Serial.println(cmd);
if (cmd == 'F') { // Forward
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
Serial.println("You pressed F");
//motor4.run(FORWARD);
}
else if (cmd == 'B') { // Backward
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
//motor4.run(BACKWARD);
}
else if(cmd == 'L') { // Left turn
motor1.run(BACKWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
//motor4.run(FORWARD);
}
else if (cmd == 'R'){ // Right turn
motor1.run(FORWARD);
motor2.run(BACKWARD);
motor3.run(FORWARD);
//motor4.run(BACKWARD);
}
else if (cmd == 'S') { // Stop
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
//motor4.run(RELEASE);
}
else {
Serial.println("Didn't get anything");
}
}
}
This is the exact code I was using which worked initially, but now it isnt working at all
This is the wiring I am using, and this is the wiring from the start, I haven't changed it at all. The car just stopped running suddenly. I tried checking if there was any issue with the bluetooth module or the motors, but they work perfectly fine with any other code i upload. Only when i upload the code I gave above, it doesn't work. I was using the bluetooth terminal app available on playstore to send commands, but now the bluetooth module doesn't take commands from that app as well. Please help me out.

