'Serial read only returns reverse question marks in Blutooth connection read

I'm facing problem with my Arduino Bluetooth controller car.
I'm only getting reverse question marks.

I'm using an HC-05 Bluetooth module. The pins are connected as following:

  • HC 05 -> Arduino
  • RX -> TX
  • TX -> RX
  • 5V -> 5V
  • GND -> GND

Ardunio code:

#include <AFMotor.h>
AF_DCMotor right_motor(3, MOTOR12_8KHZ);
AF_DCMotor left_motor(4, MOTOR12_8KHZ);

String readString;

void setup() {
  Serial.begin(9600);
  right_motor.setSpeed(250);
  left_motor.setSpeed(250);
}

void loop() {
  while(Serial.available()){
    delay(50);
    char c=Serial.read();
    readString+=c;
  }
  if(readString.length()>0){
    Serial.println(readString);
    if (readString =="FORWARD"){
      right_motor.run (FORWARD);
      left_motor.run (FORWARD);
      delay(500);
    }
    if (readString =="BACKWARD"){
      right_motor.run (BACKWARD);
      left_motor.run (BACKWARD);
      delay(500);
    }
    if (readString =="LEFT"){
      right_motor.run (FORWARD);
      left_motor.run (BACKWARD);
      delay(500);
    }
    if (readString =="RIGHT"){
      right_motor.run (BACKWARD);
      left_motor.run (FORWARD);
      delay(500);
    }
    if (readString =="STOP"){
      right_motor.run (RELEASE);
      left_motor.run (RELEASE);
      delay(500);
    }

    readString="";
  }
}

Serial monitor:

Serial monitor output

I have tried many types of changes in the code, but they are not working.



Solution 1:[1]

The baud rates must be identical between Bluetooth module and Arduino Serial port. You can check the Bluetooth module baud rate by entering the following AT command: AT+UART?, also, you can change it using the following AT command: AT+UART=desired_baud_rate, stop_bit, parity_bit,\r\n.

Moreover, you can't use Serial.read() then compare the output with "STRING"! Instead, use Serial.readString();.

Solution 2:[2]

According to most documentation, the default baud rate for HC-05 is 9600, or 38400 for AT command mode. Try:

Serial.begin(57600);

I've got a half dozen HC-05 which all shipped with a default set to 57600 baud.

(I'm posting this answer in part because I just spent hours re-discovering this.)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 opendna