HC-05 Module Returning Garbage Values With Arduino Uno LED Test Android App

Hello,

I have a HC-05 Bluetooth module connected to my arduino uno board and I'd like to just test to see that it works. I have programmed it using the following code:

int LED= 13;  
char input;  
 
void setup() 
{  
 Serial.begin(9600);  
 pinMode(LED, OUTPUT);  
 Serial.println(">> START<<");  
}  
 
void loop() 
{  
 if(Serial.available()>0)  
 {  
   input= Serial.read();
   Serial.print(input);
   Serial.print("\n");  
   
   if(input=='1')  
   {  
     Serial.println("ON");  
     digitalWrite(LED, HIGH);  
     delay(2000);  
   }  
   else if(input=='0')  
   {  
     Serial.println("OFF");  
     digitalWrite(LED, LOW);  
     delay(2000);  
   }  
   else  
   {  
     Serial.println("NO INPUT");  
     Serial.println(input);  
   }  
 }  
   
}

The layout of the hardware is attached.

Now when I open a Bluetooth Terminal App or LED app or Ardudroid app, no matter what and send a 0 or 1, I get back garbage values.

I have attached the garbage values.
As you can see, I get a reversed question mark and NO INPUT. This means I am not receiving the 1 or 0 that I should be when using the android apps. Any idea what is going wrong?

FXV32RAI8SLPA3L.MEDIUM.jpg

You cannot use the serial monitor when you have the HC05 connected to hardware serial (pins 0 and 1). Only one device can be connected to a port at a time. Set up a software serial port to talk to the HC05 and then you can use the hardware serial and serial monitor to see what the HC05 sends. There is a software serial library that comes with the IDE. Easy to use but not as good as NeoSoftSerial or AltSoftSerial.

Connecting the HC05 RX directly to the Uno TX is risking damaging the HC05 RX input. Better to use a voltage divider to bring the Uno 5V TX signal down to 3.3V for the HC05.

Here is a quick test code showing how to use software serial. Mind that pin 4 on the Uno goes to the HC05 TX and pin 7 on the Uno goes to HC05 RX through a voltage divider (1K TX to HC05 RX, 2.2K HC05 RX to ground).

#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 7); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);  

  mySerial.begin(9600);
  mySerial.println("Hello, world?");  // send to BT
}

void loop() 
{ // run over and over
  if (mySerial.available()) 
 {
    Serial.print(char(mySerial.read()));
  }
  if (Serial.available()) 
 {
    mySerial.write(Serial.read());
  }
}

Hey, thanks for the reply.

So I did what you said. I made a voltage divider to lower the TX signal from the Uno down to 3.3V. And used your program. However I am still getting the junk characters. Is it a problem with the bluetooth module itself? I've attached what I'm getting on the monitor.

Also, when I transmit something over bluetooth to the module, the transmit TX LED flashes for a second on the Arduino Uno board, so it's definitely receiving something..

EDIT: I THINK I MAY HAVE FIXED IT. I edited your code and set the baud rate to 115200 and the serial monitor to the same. I then get the data. Thank you. I'll let you know if anything goes wrong now.

groundFungus:
You cannot use the serial monitor when you have the HC05 connected to hardware serial (pins 0 and 1). Only one device can be connected to a port at a time. Set up a software serial port to talk to the HC05 and then you can use the hardware serial and serial monitor to see what the HC05 sends. There is a software serial library that comes with the IDE. Easy to use but not as good as NeoSoftSerial or AltSoftSerial.

Connecting the HC05 RX directly to the Uno TX is risking damaging the HC05 RX input. Better to use a voltage divider to bring the Uno 5V TX signal down to 3.3V for the HC05.

Here is a quick test code showing how to use software serial. Mind that pin 4 on the Uno goes to the HC05 TX and pin 7 on the Uno goes to HC05 RX through a voltage divider (1K TX to HC05 RX, 2.2K HC05 RX to ground).

#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 7); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

mySerial.begin(9600);
  mySerial.println("Hello, world?");  // send to BT
}

void loop()
{ // run over and over
  if (mySerial.available())
{
    Serial.print(char(mySerial.read()));
  }
  if (Serial.available())
{
    mySerial.write(Serial.read());
  }
}

1 Like

If you are sending from the HC05 to the Uno, the RX should flash on the Uno, not TX. You have pin 4 of the Uno going to TX on the HC05 and pin 7 of the Uno going to the voltage divider and HC05 RX? Are you sure that the baud rate setting on the HC05 is 9600?

I just tried the code that I posted with my Andriod tablet and Bluetooth Terminal and it works fine (to Uno and HC05). I don't know what the problem is on your end.

groundFungus:
If you are sending from the HC05 to the Uno, the RX should flash on the Uno, not TX. You have pin 4 of the Uno going to TX on the HC05 and pin 7 of the Uno going to the voltage divider and HC05 RX? Are you sure that the baud rate setting on the HC05 is 9600?

I just tried the code that I posted with my Andriod tablet and Bluetooth Terminal and it works fine (to Uno and HC05). I don't know what the problem is on your end.

Hey, I set the baud rate to 115,200 on the code you provided and it started to work..don't know why it was pre-set to that as I didn't set it. Thank you anyway.