1

I have this sketch that I got as a sample. I have the two HC-05s connected. What I type in one serial monitor shows up on the other, but as question marks. The most common reason for this I find is baud rate doesn't match. I didn't change the baud rate on the HC-05s when I got them, so I assume they are set to default. I can put them in command mode and ensure the baud rate is set.

Does the baud rate of the HC-05s have to match the baud rate of the Serial monitor? I would assume not. I am also wondering if this is a problem with formatting a char[] when writing to the serial display.

#include <SoftwareSerial.h>
SoftwareSerial BTserial(7, 8); // RX | TX
// Connect the HC-05 TX to Arduino pin 7 RX. 
// Connect the HC-05 RX to Arduino pin  8 TX through a voltage divider.
// 

char c = ' ';


void setup() 
{
Serial.begin(9600);
Serial.println("Arduino is ready");
Serial.println("Remember to select Both NL & CR in the serial monitor");

// HC-05 default serial speed for AT mode is 38400
BTserial.begin(38400);  
}

void loop()
{

// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTserial.available())
{  
    c = BTserial.read();
    Serial.println(c);
}

// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available())
{
    c =  Serial.read();
    BTserial.write(c);  
}
}
  • It was the baud rate. I read the baud rate from the bluetooth modules, it was set to 9600. I tweaked the code and its working now – David Green Feb 11 at 1:26
  • Both of these comments should be answers @jsotola – RubberDuck Feb 11 at 10:55
  • @jsotola thanks. I didn't think so. – David Green Feb 11 at 17:40
1

No, they do not need to match.

You are talking about two separate serial port connections.

The baud rate between the HC-05 and the Arduino (BTserial) has to match.

The baud rate between the Arduino and your PC (Serial) has to match.

BTserial and Serial can use different baud rates.

An overflow problem can arise if a lot of data arrives from the HC-05 and there is not enough memory to store it until it can be forwarded to Serial.

schematic

simulate this circuit – Schematic created using CircuitLab

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.