HC-05 Not responding to any commands

I originally tried to send data from an android phone to the bluetooth module-connected arduino uno.

Wiring:

5V UNO ------- Vcc HC-05
G UNO -------- GND HC-05
11 UNO ------- Tx on HC-05
10 UNO ------- Rx on HC-05

and I uploaded this sketch:

#include <Servo.h>
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(11,10); //Rx, Tx method signature
Servo myServo;

void setup() {
  delay(1500); // wait for bluetooth module to start
  bluetooth.begin(9600); 
  Serial.begin(9600);
  myServo.attach(7);
  Serial.println("Ready");
}

void loop() {
  // put your main code here, to run repeatedly:
  if(bluetooth.available()>0) {
    Serial.println("Waiting for data");
    int c = bluetooth.read();
    bluetooth.println(c);
    if(c=='1'){
      bluetooth.println("Open Wide");
      Serial.println("1");
      myServo.write(1000);
    } else if(c=='2'){
      bluetooth.println("Close");
      Serial.println("2");
      myServo.write(2000);
    }
  }  
}

Yes I did have a servo connected to pin7 but that never ran upon sending 1 to the arduino via Serial Bluetooth Terminal app on Android. Im able to connect to the hc05 but when I send the commands nothing is received either in the serial monitor or on the android app terminal or on the servo pin 7.

So I decided to check the at commands and I uploaded this sketch to the arduino:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(11,10); // RX, TX
void setup() {
  Serial.begin(9600);
  pinMode(9,OUTPUT); 
  digitalWrite(9,HIGH);
  Serial.println("Enter AT commands:");
  mySerial.begin(38400);
}

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

I tried with a wire from pin 9 to the enable pin of the hc05, nothing.

I tried without the wire to pin 9 but holding the button on the hc05 while powering up, nothing.

By nothing I mean, i get the "Enter AT commands" in the serial monitor but when I enter AT or AT+NAME, I get nothing back.

Here is a picture of the module:

It has a BCM417 chip i see:

I just noticed that I can connect to it from a serial bt android app and when I send commands from the phone to the hc05 I get nothing in the SM but when I send from the SM to the app at least I get junk.

The fact that you get anything suggest there is nothing seriously wrong - unless you are imagining things. The fact that you get junk might indicate that you may be simply running on the wrong baud rate. Since you don’t know what you are doing, set all baud rates to default - 9600, including the serial monitor. If you really need to configure Bluetooth, which is probably not the case, go to the Martyn Currey website and learn how to configure it properly. That Bluetooth has a button on it, which absolves you from messing about with bits of wire.

Yes I know the button puts it into Command mode and it does blink 1x/2secs but even so I havent gotten it to respond. So I tried:

  1. 9600 both (w/ 2nd debug sketch) = nothing
  2. 19200 nothing
  3. 38400 nothing
  4. 57600 nothing
  5. 115200 nothing

So I checked to make sure I wasnt imagining things and recorded this video. Here the sketch is at 9600 for both Serial. and bluetooth. and the hc05 is not in Command mode, instead Ive connected to it from the Serial BT android app and I send data to it from the SM:

Video

What are you expecting?

You enter "hi there" in the serial monitor and it appears on the phone.

That is what this code does.

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

Yes but :

  1. In that same debug sketch, comm only works in one direction, from SM to phone, not vv.

  2. Another thing that doesnt work is when I try to put it into AT Command mode. And my original sketch, the servo one, doesnt work either. Its supposed to move the servo when it receives the 1 and 2, but it doesnt.

Oh and I am using the 1/2k voltage divider and it doesnt change anything.

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

??
I only assume it can be simplified that much, I actually did what Martyn Currey told me to do.

#include <SoftwareSerial.h>
SoftwareSerial BTserial(8, 9); // RX | TX

char c=' ';
boolean NL = true;

void setup() 
{
   Serial.begin(9600);
   BTserial.begin(38400);  
   Serial.println("BTserial started ");
}

void loop()
{
    // Read from the Bluetooth module and send to the Arduino Serial Monitor
   if (BTserial.available())
   {
       c = BTserial.read();
       Serial.write(c);
   }
 
   // Read from the Serial Monitor and send to the Bluetooth module
   if (Serial.available())
   {
       c = Serial.read();
       BTserial.write(c);   

       // Echo the user input to the main window. The ">" character indicates the user entered text.
       if (NL) { Serial.print(">");  NL = false; }
       Serial.write(c);
       if (c==10) { NL = true; }
   }

In that same debug sketch, comm only works in one direction, from SM to phone, not vv.

Are you certain that you have the module TX to the software serial RX?

If the module RX is connected properly to the SS TX, but, for example, you have made an error and connected the state pin instead of the TX pin to the SS RX you will see the one sided operation that you do.

Your code works bidirectionally for me when I have ss and serial at 9600, and I leave out the pin 9 stuff.

Module TX - UNO Pin 11
Module Rx - Voltage Divider (1k/2k) GND - UNO Pin 10

And I just updated my code to this:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10,11); //Rx, Tx
void setup() {
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  mySerial.begin(9600);
}

void loop(){
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}
SoftwareSerial mySerial(10,11); //Rx, Tx

The software serial constructor is from the point of view of the Arduino. The module Tx gets connected to the Arduino Rx. You have it backwards here.

Module TX - UNO Pin 11
Module Rx - Voltage Divider (1k/2k) GND - UNO Pin 10

ok so I had:

UNO 10 - 1kΩ - Rx BT &
UNO 11 - Tx BT

& this code:

SoftwareSerial mySerial(10,11); //Rx, Tx

Now I have

UNO 11 - 1kΩ - Rx BT &
UNO 10 - Tx BT

and that is when I get data sent from the SM to the phone app which is connected to the HC05. So yes, I did foul up there but thats only because in my OG sketch in #1 I had:

SoftwareSerial mySerial(11,10); //Rx, Tx

but now Im using 10,11 just to keep things ordered in my head. I have just tested it again quite a few times. With the servo sketch I get no movement of the motor that should spin upon receiving the command from the phone app and I get nothing written in the SM either because in my code i have a Serial.println to write the received command and thats not happening either.

With the debug sketch comm still continues in only one direction, SM-Arduino-BT-Phone app, but not in the opposite direction. And the fact that I cant seem to get it to respond to AT commands even though it shows to be in Command mode according to the LED after powering up with the button.

Rebooted my IDE and it works now