Bluetooth Module HC-05 is not working with Arduino Uno

I am currently testing Bluetooth Module HC-05 but it is not working with Arduino Uno.
this are the cases:
case 1:
i tried using Pin 1 and Pin 0 to my Arduino, connected to HC-05. so basically Rx > Tx and Tx > Rx. according to RandomNerdsTutorial, a common mistake to connect Rx>Rx etc. i also removed the Tx and Rx wiring first before uploading the code then reconnect them after uploading code. so I uploaded a simple connection code(see code below).
Now i tried to open my Laptop/Phone to connect my Bluetooth to HC-05. i did try to Scan and HC-05 did appear anyway. Okay, so i clicked it, then i enter password 1234, it did say "You are read to go!" so it means i successfully Paired with my HC-05 right?
but this is where the problems comes in: when i checked my connection with my HC-05 in my Phone or Laptop(i tried each one first in every attempt). and on my Paired Devices, i clicked HC-05. it says: Paired and there is NO "Connect" or "Connect to this Device" just paired. so basically it is Paired but NOT or CANNOT connect with the device. so i cant connect?

Case 2:
so i tried the same thing except i use Pin 10 and Pin 11 as Rx and Tx using library <SoftwareSerial.h>, instead of actually using Pin 0 and Pin 1 in Arduino. so i did the same method, removed the Tx and Rx wire. upload the code, rewire back. then again i removed/forget the previous connection then re-Scan and Paired with the device. but again, i cannot Connect. only "Paired".

Case 3:
so little annoy since i almost stuck with this for half day figuring out. i tried to configure my Bluetooth. i use Pin 9(Arduino Uno) and connect Pin Key(of HC-05). so i can access the Serial Monitor and send commands. did the same thing. upload code, rewire etc. then access the Serial Monitor in my IDE and enter Commands like AT+NAME or other Bluetooth configuration. Nothing appeared in my Terminal.

----Question------
so the common problem is, it doesnt Connect. Yes it appear in Scanning, i can enter password and get wrong(intendedly enter wrong password just to test) or successful password. BUT it doesn't Connect. just "Paired" or "Removed Device". also, for Case 1 and 2. my Bluetooth HC-05 is still blinking even it is "Paired" or not discovered/paired by any devices. to the videos i watch their HC-05 doesnt blink unless you gave them command(like pressing switch or sending command/text thru phone, to what i saw in tutorials)

so can anyone knows what could be wrong? i have 3 Module here from different store each and 2 Arduino i tested it each but all failed(which why it took me halfday)

im assuming there is nothing wrong with my Code----atleast to my best guess, but somwhere down the process i probably made a misstep or something. A strong and huge appreciation if anyone can help me

Materials: Arduino Uno R3, HC-05 Module, 1K Resistor, 3k Resistor.
End Device: Samsung Galaxy S, Acer Nitro 5

Code(for non-software serial. simpyl removed the first 4 line and (rxPin, INPUT), (txPin, OUTPUT), and mySeral.begin(38400):

#include <SoftwareSerial.h>
#define rxPin 11 //
#define txPin 10 //
SoftwareSerial mySerial = SoftwareSerial(rxPin,txPin); //rx | tx

void setup() {
 // pinMode(keys,OUTPUT);
  //digitalWrite(keys,HIGH);
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  mySerial.begin(38400);
  Serial.begin(38400);
}

void loop() {
 mySerial.read(); // put your main code here, to run repeatedly:
  if(mySerial.available()>0){
    mySerial.println("connected");
  }
}

Wiring and screenshot of my device not "Connected":

I don't know if this is the problem but I think that 1.1 k (really?) and 3.3k aren't a good 5V voltage divider to get up to 3.3V (V=5R1/(R1+R2)=51.1/4.4=3.75V).
Try replacing the resistors with a more common 1.2k and 2.2k, and let me know.

rxPin is Arduino Input from HC
txPin is Arduino output to HC

rxPin should go to HC TXD
txPin should go to HC RXD (via voltage divider)

1. Be sure that the connection between BT and UNO is done as per Fig-1.
HC5-uno
Figure-1:

2. Pair your Android phone with BT.
3. Upload the following sketch in UNO.

#include <SoftwareSerial.h>
SoftwareSerial SUART(10, 11); // SRX = 2, STX = 3
#define ledpin 13  //built-in L of UNO

void setup()
{
  pinMode(ledpin, OUTPUT);
  digitalWrite(ledpin, LOW);  //L is OFF
  Serial.begin(9600);
  SUART.begin(9600);
}

void loop()
{
  if (SUART.available())
  {
    char x = SUART.read();
    if (x == 'Y')
    {
      digitalWrite(ledpin, HIGH);  //L is ON
    }
    if (x == 'N')
    {
      digitalWrite(ledpin, LOW);    //L is OFF
    }
  }
  if(Serial.available())
  {
    char c = Serial.read();
    SUART.write(c);
  }
}

4. Open ASCII Mode BT terminal in phone, which communicates at Bd = 9600 with BT.
5. Send Y from BT and check that L (built-in LED) of UNO has turned ON.
6. Send N from BT and check that L (built-in LED) of UNO has turned OFF.
7. Open SM in the Arduino IDE with No line ending option in the Line ending box..
8. Enter 123 in the InputBox of Serial Monitor and then click on Send Button.
9. Check that 123 has appeared on the BT terminal of phone.

2 Likes

Hi GolamMostafa. so thinks here to update:

first i tried the two suggestion before you. then eventually tried yours.
so here's a thing. i first in respect to step 2 i first Forget Paired the HC-05 from my Android phone then configure the Pins. then i proceed to connect them...well precisely: i Scan then enter password then "PAIRED" them. then next, i uploaded the code to my Arduino.

in step 4, im not sure if I follow this correctly, i first download Serial Bluetooth Terminal App. (https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&hl=en&gl=US)
then on the App i selected "Device" and search for HC-05. then I connected them. then finally to your next steps. i first sent Y then N and it did blink the LED.
then i went to my Arduino IDE, set it to Serial.begin(9600) i did enter 123, it did not appear in the Serial Monitor. and nothing actually outputted in my Serial Monitor. but the 123 i sent did appear in my Terminal App.

is this really how it should work? so there shouldn't be "Connected" label and "Paired" is enough?
because im confused since i was expecting like in my Bluetooth Icon(right) it the "HC-05" text didnt appear below the Blueetooth text, which is what usually happen when i connect it to a device like my Earphone. or unlike my ESP32 when i connect it to my phone's WiFi the name appears.

Let me know if something is still off. unfortunately it is already late night here so i cant test anymore.but ill test more tomorrow ASAP. i Appreciate everyone's help!

You have been able to communicate among your phone, UNO, and Serial Monitor. Thanks a lot for the great achievement. Congratulation!

Thanks Golam. so far i think its ok. i tested it with servo and i seems fine. with exception that sometimes it lost power, i guess 5v isnt enough? maybe ill try get 7.2 Battery(i have 2x Li-On Battery so 3.7+3.7 would probably do) and test it.

I just have one more question: how i would make my Arduino send DATA to my Bluetooth App Terminal? so the thing is i did send Y and N like you said from Phone-to-Bluetooth Arduino and turn on and off the LED. i did send one from a Serial Monitor to my Bluetooth App too like the 123.

But for example, I removed my Arduino connected to my PC(which means i cant access the Serial Monitor, send 123 etc since no longer connected) and make my Arduino-BT power on using Batteries etc. then i program my Arduino that it should send "Hello World" in my Bluetooth Terminal App in my Phone?.... ... .. .or i have a Joystick in my Arduino+BT, then i interact with my Joystick so the Arduino+BT should send X and Y axis data to my Bluetooth Terminal App in my Phone? I figured out some basic of Phone BT Terminal -> Arduino, now maybe i should also test Arduino -> Phone BT Terminal

....either of Hello World or Joystick. How would my Arduino send data/text/int/char to the app/Bluetooth Terminal App in my Phone?

I appreciate everyone's help once again!

Connect switch K1 (with internal pull-up resistor) at DPin-2 of UNO. Create sketch so that when you press K1, the message "Hello World" will appear on BT Terminal of Phone.
Hints:

char myMsg[] = "Hello world";
pinMode(2, INPUT_PULLUP);
while(digitalRead(2) != LOW)
{
     ; //wait until K1 is pressed
}
SUART.print(myMsg);

Hi i finally made it. i manage to print a text from my Bluetooth -> Android Phone. Thank you so much!
Just very last question this is why it took me 1-2days to reply since im trying to figure this one out:

In your code you are doing char msg[]="hello world";
How can I send Int or Float instead?
specifically i have like Joystick here and trying to send the value/data of my joystick X-axis atleast for now. so basically the output that im trying to show in my android bluetooth terminal is a read char/int/float data, not a fixed variable/text
For my jostick code it is:

  int X_Axis = analogRead(X_Joy);
  char x_Ax[0] = map(X_Axis, 0, 1023, -512, 512);
  BTSerial.write(X_Ax); //or
  BTSerial.print(X_Ax);

but nothing works. basically it just send random characters in my device. im assuming it doesnt let me print.
i also tried something else Rather than doing data-from-a-sensor-or-input, I first i tried to make a fixed int variable. For example:

Int NumberMessage = 13;
BTSerial.print(NumberMessage);  //or 
BTSerial.write(NumberMessage);

but once again it just sending random characters. so i went and tried this. basically ill make a char array[], put the Int inside that char array[] then print the char array[]:

char NumberMessage[] = ""; //it doesnt allow me/cause error if i left this
int Number = 20;
NumberMessage[0] = 20;
BTSerial.print(NumberMessage) //or
BTSerial.print(NumberMessage[0]);
BTSerial.print(Number)//for directly printing an INT instead of relying on char

However it doesnt print anything as i expected. the first BTSerial.NumberMessage prints random character while the BTSerial.print(NumberMessage[0]) print blank. i assume it is the "" in tha char NumberMessage[]. while the print(Number prints random characters again.

so the overall problem, how can i print Int/Float or Number text(if i would convert it to char/string) without having a "fixed message" just like your Hello World?
I apologize if it may seems confusing. but ultimately im trying to send an Int value from a sensor's input/data. i tried printing it directly as INT or putting the read data/int in a char Arrayx[1] then print the Arrayx or Arrayx[1] but nothing works.

This is really the last problem im encountering. i have manage to learn how to rename my HC-05, AT Command. so far this is the last problem i have...

Try the following sketch:

#include <SoftwareSerial.h>
SoftwareSerial SUART(10, 11); // SRX = 2, STX = 3
#define ledpin 13  //built-in L of UNO
unsigned long presentMillis = millis();

void setup()
{
  pinMode(ledpin, OUTPUT);
  digitalWrite(ledpin, LOW);  //L is OFF
  Serial.begin(9600);
  SUART.begin(9600);
}

void loop()
{
  if (SUART.available())
  {
    char x = SUART.read();
    if (x == 'Y')
    {
      digitalWrite(ledpin, HIGH);  //L is ON
    }
    if (x == 'N')
    {
      digitalWrite(ledpin, LOW);    //L is OFF
    }
  }
  if (Serial.available())
  {
    char c = Serial.read();
    SUART.write(c);
  }
  
  if (millis() - presentMillis >= 1000)
  {
    //int X_Axis = analogRead(X_Joy);
    int x_Ax = map(421, 0, 1023, -128, 127);
    SUART.println(x_Ax); //
    SUART.println(12.75, 2);
    SUART.println("===========");
    //BTSerial.print(X_Ax);
    presentMillis = millis();
  }
}
1 Like

Hi! it seems it is now working. there was some problem at first because i was being tooo strict in Char. now after reading your code and reviewing my code. i think i have solved it. I can now send Int and Float to the Android. Ok i think thats pretty much what i need to learn. the rest is on my own now. i am quite done with HC-05/Bluetooth Basics and start on slightly higher form of Bluetooth project but the rest should be on my own now. I'm satisfied with the current result already

Up next will be communicating 2 HC-05 to each other like Master and Slave Bluetooth. like sending Joystick's data to a dc motor etc. but that would be for another time(and another forum incase im stuck on something).

I APPRECIATE EVERYONE'S HELP!!!

1 Like

i hope im not late. but i would like to ask something. is it possible to send 2 data(ex: Int A=50 and Int B=100) in 1 go? in this case you manage to send a Hello World but it is inside a single char array. but what if for example i wanted to do 2 data of Int. Basically i have 2 Arduino with HC-05 paired/connected wirelessly to each other. the first one has 2 potentiometer that will sent both data , and the other will receive both data.

so what i was trying to find out is send 2 data at the same time. but with more uniformed(if that is the correct term). basically ill send a the 2 data in 1 go, the 1st potentiometer reading will be declared first and the 2nd potentiometer reading will be declare next. so there is a fixed uniform/arrangement. then the other arduino will know that in the variable i sent it contains 2 data, and it knows that the 1st data is for LED1 and the 2nd data is for LED2.
like:
1st HC-05/Arduino

BlueToothSerial.write(Potent1);
BlueToothSerial.write(Potent2);

2nd HC-05Arduino

x = BlueToothSerialSerial.read(); 
y = BlueToothSerialSerial.read();

but what if there is more efficient way? because what im worried/confuse is what if the y=Serial.read() reads the Potent1. etc, i cant think of a way how to point specifically that y=Serial.read() should read the Potent2...or since Potent2 was the last variable sent, maybe even x=Serial.read() would read the Potent2 instead of Potent1 since it may overwrite what was written. so i was trying to think how it will be done. for example like an array:

int Arrays[] = {Potent1, Potent2};
BlueToothSerial.write(Arrays[]);

and the other side is:


x=BlueToothSerial.read(Arrays[0]);
y=BlueToothSerial.read(Arrays[1]);

I tried this but it only causes error. Anyway, my main question is, is it possible(and how) can i send 2 data in 1 Serial.write(2data); then the other HC-05/Arduino could understand that the variable was sent contains 2 data?

I hope my explanation/concept is understandable. I apologize for ambiguous question.

1. Assume you have the follow data:

int A = 50;
int B = 100;

2. Sender codes:

BlueToothSerial.print('<'); //beginning mark of message
BlueToothSerial.print(A);
BlueToothSerial.print(',');  //data item separator
BlueToothSerial.print(B);
BlueToothSerial.print('>'); //ending mark of message

3. Receiver Codes:

char myData[20];
char *token;

void setup()
{
  Serial.begin(9600);
  SUART.begin(9600);
}

void loop()
{
  byte n = SUART.available();
  if (n != 0)
  {
    char y = SUART.read();
    if ( y == '<')
    {
      byte m = SUART.readBytesUntil('>', myData, 20);
      myData[m] = '\0';
      token = strtok(myData, ",");
      int A = atoi(token);
      Serial.print("1st data: "); Serial.println(A, DEC);
      //-------------------------------------------------
      token = strtok(NULL, ",");
      int B = atoi(token);
      Serial.print("2nd data: "); Serial.println(B, DEC);
    }
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.