HC-05 gibberish in serial monitor

Hi, I am relatively new to Arduino and such and had a problem with my HC-05 setup. I have looked around and my exact issue is on the forums already however my situation is a bit unique and I couldn't quite get the answer I was after.

Basically the problem is on the Serial Monitor attempting the command "AT" results in outputs such as 'xxxx?x', which is exactly what some other users had.

I am using Arduino Uno with an Adafruit motor controller shield, which unfortunately steals literally every single pin so I have had to modify it (hence why I believe my situation is "unique"). I cut pins 0 and 1 off and soldered some power pass through pins. So I currently have the pin that says RXD on the actual module itself plugged into 0, and the one saying TXD plugged into 1. I do not have a voltage divider installed, so the board is receiving 5V. I know that it runs on 3.3 and have seen that using 5V can be an issue however some guides insist that you can in fact use 5V, and they have wiring diagrams to support that.

Uploading code is a bit difficult since I have to unplug it every time because Arduino wont let you upload with anything plugged into 0 and 1. So essentially I unplug pins 0 and 1, upload code, plug them back in.

So the code I am using is this:

#include <SoftwareSerial.h>

//Change these to whatever pins you're using
SoftwareSerial blueSerial(0, 1); // RX, TX

void setup()
{
  Serial.begin(9600);
  blueSerial.begin(38400);
  pinMode(9, OUTPUT);
  digitalWrite(9, HIGH);
}

void loop()
{
  if (blueSerial.available())
  {
    Serial.write(blueSerial.read());
  }
  if (Serial.available())
  {
    blueSerial.write(Serial.read());
  }
}

And then opening serial monitor and typing commands yields what I had said before. The response does differ depending on what command I give, but I don't know whether that is a board rate thing or not. I have tried a few combinations of board rate option in the serial monitor, but to no avail.

Last thing: I think the module needs to be in AT mode for this to work, and guides say it is in this mode when the LED blinks "slowly". I don't really know how "slowly" it should be blinking but regardless of whether I press the button onboard or not it blinks at a rate of about 4-5 times per second. Sorry for long post here, I wanted to give every piece of information I had in the hopes that that would result in an easier resolution.

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the IDE 1.x category.

You can not use pins 0 and 1 for two things at the same time. On the Uno, those pins are used for the communication with the PC; using them for different things at the same time will cause problems. You will have to move your SoftwareSerial to other pins; I'm not that familiar with SoftwareSerial but you can consider using the analogue pins (e.g. A0 and A1).

Which one? Please post a link.

I have some doubts :wink: The fact that the headers are fully populated does not mean that all pins are used.

There is a tutorial on using the Adafruit Motor Shield at:
https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino

Here is a quote from that tutorial:

Instead of using a latch and the Arduino's PWM pins, we have a fully-dedicated PWM driver chip onboard. This chip handles all the motor and speed controls over I2C. Only two GPIO pins (SDA & SCL) plus 5v and GND. are required to drive the multiple motors, and since it's I2C you can also connect any other I2C devices or shields to the same pins.

So only 2 pins are used for motors.

Two further pins (D9, D10) are used for servos. They are only connected to the servo header pins , so they could be used for other things if servos aren't being used.

Oh okay, well clearly my inexperience shows, to me it seemed that every pin had a trace that went somewhere which seemed important, and actually at one stage I wanted to use analogue pins, I will give that another go.

I've arrowed the pins that are used on the Adafruit photos below:


All the other digital pins are available, and are conveniently connected to a second row of pads for easy connection.

Move your connections from D0 and D1 to some other pins and adjust the pins used by SoftwareSerial to suit.

Have done this, moved pins to A0 and A1 however am getting no response at all. I cannot tell if it is because I have soldered poorly, or if I have declared the analog pins to be used incorrectly. I will solder some more analog pins and try those.

Edit: soldered 3 more pins on top of the 2 I already had, and all 5P2 (P because order may be wrong)=20 combinations produce no response. Clearly I am doing something wrong.

Edit 2: I decided to remove the motor controller shield from the equation entirely and plug in the TX of the HC-05 into pin 2 and the RX into pin 3, however this also results in no response, even after changing the softwareserial values in the code. It seems that only pins 0 and 1 give any type of response at all, however the response is gibberish. Again I wonder if my HC-05 is in AT mode at all because it is flashing fairly quickly, when guides say it should blink "slowly" in AT mode.

Then start at the beginnning; remove / disconnect the motor shield and test again.

Note:
If you update code, you should post the updated code on a new reply. If you did not update the code, there is no surprise that it does not work.

Okay, I will put the code here that I used with the HC-05 TX plugged into pin 2 of Arduino directly and the RX plugged into pin 3:

#include <SoftwareSerial.h>

//Change these to whatever pins you're using
SoftwareSerial blueSerial(3, 2); // RX, TX

void setup()
{
  Serial.begin(9600);
  blueSerial.begin(38400);
  pinMode(9, OUTPUT);
  digitalWrite(9, HIGH);
}

void loop()
{
  if (blueSerial.available())
  {
    Serial.write(blueSerial.read());
  }
  if (Serial.available())
  {
    blueSerial.write(Serial.read());
  }
}

What's the other side of the bluetooth connection? Cell phone or computer (which one)? Running which application?

As far as I can see there is not much wrong with your code. Only thing might be that you're pushing the limits of SoftwareSerial; 19200 would be more safe.

Did you modify the HC-05 to communicate with the Arduino at 38400? Or is it still configured for 9600 baud?

You need to connect the TX pin of the bluetooth module to the RX pin on the Arduino, and the RX pin on the bluetooth module to the TX pin on the Arduino.

You are connecting TX to TX and RX to RX.

I tried it reversed and am already aware, so if this is an issue, this is not the only one. There is no bluetooth connection at the moment, I am simply connected via USB to the Arduino and am trying to check the configuration so I can set up something to be able to connect to the module in the first place.

Just because someone posts a schematic doesn't mean it is correct.

You need to connect the Arduino TX pin through a potential divider so that the HC-05 RX pin only sees 3.3V.

See Martyn Currey's website for useful information. He's an expert .
http://www.martyncurrey.com/hc-05-with-firmware-2-0-20100601/#Connecting-to-an-Arduino

This is from his site:
HC-05_2.0-20100601_Circuit_01_800-345x300

You need something to communicate with. My knowledge of Bluetooth is limited. To my knowledge, unless you are in AT mode, the module does not send replies; it's the device (e.g. your cell phone) at the other side that does.

What I think I know

  1. There is a way to get it in AT mode with a wire or button.
  2. Your baudrate needs to match.
  3. You can use a PC and a terminal program (e.g. Serial monitor) to configure your Bluetooth module; you do not need a sketch but need to keep the Arduino in reset with a jumper wire. In that case you need to use pins 0 and 1.

Pretty simple to send "Hello", delay(1000),. . .
from the HC05 and see it on the mobile's serial terminal, establish that much is working
(Arduino 'TX' pin to HC 'RX' pin, via that voltage divider arrangement).

Okay, I will try that. I will say the amount of guides saying you can use 5V and the amount saying you must use 3.3V seemed similar in number from a brief search, so I could not tell which was correct, so thanks for the clarification.

see it on the mobile's serial terminal

I strongly recommend you use Kai Morich's Serial Bluetooth Terminal app.

It is simple to use, easy to configure, rock solid, and successfully used by many on this forum.

For context, I am basing it off this guide here:
https://core-electronics.com.au/guides/how-to-use-bluetooth-modules/
I have read it again and it has occurred to me that I don't quite follow the part about getting it into AT mode, particularly in the case where the module has a button. It is definitely clear that I haven't yet been able to get it into AT mode, when I get home I will try to get it into AT mode first and then see if it works.

As an aside, do I actually need to do any of this AT mode configuration? I am planning on connecting my computer to the module via bluetooth and sending commands which will then get sent to the motor controller, if I can just connect directly than what I am doing is a bit silly and redundant. Anyway, thanks for the help so far.

Typically not. The HC05 in it's default mode is set as a slave and 9600 baud. That's typically all that's need to communicate with a phone. Setting a PC bluetooth adapter as a master may be more involved.

Okay, thanks, I have gotten it connected to my laptop on port COM4, and now I just need to make some code to do a quick test. I have a 5V bulb with resistor inside which I can plug into whichever port I'd like, and I want that when I type "1" into the serial monitor the light turns on, and if I type 0 it turns off. What would code look like that would do this for me? I have given it a go already with the bulb plugged into 13 and ground but I am pretty sure there are multiple things wrong with this code/setup (I am new to c++) here since right now typing into COM4 serial monitor does nothing to the bulb at all:

#include <SoftwareSerial.h>

//Change these to whatever pins you're using
SoftwareSerial blueSerial(3, 2); // RX, TX

void setup()
{
  Serial.begin(9600);
  blueSerial.begin(9600);
  pinMode(9, OUTPUT);
  pinMode(13,OUTPUT);
  digitalWrite(9, HIGH);
}

void loop()
{
  if (blueSerial.available())
  {
    Serial.write(blueSerial.read());
    int data = blueSerial.read();
    Serial.print(data);
    if (data =='1')
      digitalWrite(13,HIGH);
  }
  if (Serial.available())
  {
    blueSerial.write(Serial.read());
    int data = Serial.read();
    Serial.print(data);
    if (data =='1')
      digitalWrite(13,HIGH);
  }
}

You have this twice:

if (data =='1')
      digitalWrite(13,HIGH);

I guess you'll need to do something as a consequence of '0', too.

Did you succeed at getting "Hello" repeating on your mobile?

A simple example (of serial data) to consider --

char inChar;

void setup() 
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
}

void loop() 
{
  if(Serial.available() > 0)
  {
    inChar = Serial.read();
    if(inChar == 'N')
    {
      digitalWrite(13, HIGH);
      delay(2000);
      digitalWrite(13, LOW);
    }
  }
}