Bluetooth HC-05 & ArduDroid - Hello World

Device: Arduino UNO

I think I have my HC-05 working and wired correctly. I was able to launch ArduDroid and connect to the HC-05 and I can see my name come up "Kevin Test: in the test GET DATA area of the app:

The problem I think is that I am not able to send data or control the LED light (in below picture). You can see the red wire plugged from the positive terminal of the red LED into PIN 11 on the Arduino. The problem is in ArduDroid app when I slide the bar for 11 in the app, the LED light is not responding. Is there a test I can do to send data to the HC-05 to make a light blink or send a message from the app to the Terminal window in the Arduino application on my PC? I know the LED is wired correctly, I was able to modify the code in a test to make it manually blink on pin 11.

Here is the original wiring diagram I followed except I had to daisychain two 1k resistors and I didnt put a resistor on the LED ground because I am running 3.3 volts through the board and wont have the LED on long anyway.

Here is the tutorial and code I used

/*
 PROJECT: ArduDroid 
 PROGRAMMER: Hazim Bitar (techbitar at gmail dot com)
 DATE: Oct 31, 2013
 FILE: ardudroid.ino
 LICENSE: Public domain
*/

#define START_CMD_CHAR '*'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUDROID 13
#define MAX_COMMAND 20  // max command number code. used for error checking.
#define MIN_COMMAND 10  // minimum command number code. used for error checking. 
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2

String inText;

void setup() {
  Serial.begin(9600);
  Serial.println("ArduDroid 0.12 Alpha by TechBitar (2013)");
  Serial.flush();
}

void loop()
{
  Serial.flush();
  int ard_command = 0;
  int pin_num = 0;
  int pin_value = 0;

  char get_char = ' ';  //read serial

  // wait for incoming data
  if (Serial.available() < 1) return; // if serial empty, return to loop().

  // parse incoming command start flag 
  get_char = Serial.read();
  if (get_char != START_CMD_CHAR) return; // if no command start flag, return to loop().

  // parse incoming command type
  ard_command = Serial.parseInt(); // read the command
  
  // parse incoming pin# and value  
  pin_num = Serial.parseInt(); // read the pin
  pin_value = Serial.parseInt();  // read the value

  // 1) GET TEXT COMMAND FROM ARDUDROID
  if (ard_command == CMD_TEXT){   
    inText =""; //clears variable for new input   
    while (Serial.available())  {
      char c = Serial.read();  //gets one byte from serial buffer
      delay(5);
      if (c == END_CMD_CHAR) { // if we the complete string has been read
        // add your code here
        break;
      }              
      else {
        if (c !=  DIV_CMD_CHAR) {
          inText += c; 
          delay(5);
        }
      }
    }
  }

  // 2) GET digitalWrite DATA FROM ARDUDROID
  if (ard_command == CMD_DIGITALWRITE){  
    if (pin_value == PIN_LOW) pin_value = LOW;
    else if (pin_value == PIN_HIGH) pin_value = HIGH;
    else return; // error in pin value. return. 
    set_digitalwrite( pin_num,  pin_value);  // Uncomment this function if you wish to use 
    return;  // return from start of loop()
  }

  // 3) GET analogWrite DATA FROM ARDUDROID
  if (ard_command == CMD_ANALOGWRITE) {  
    analogWrite(  pin_num, pin_value ); 
    // add your code here
    return;  // Done. return to loop();
  }

  // 4) SEND DATA TO ARDUDROID
  if (ard_command == CMD_READ_ARDUDROID) { 
    // char send_to_android[] = "Place your text here." ;
    // Serial.println(send_to_android);   // Example: Sending text
    Serial.print(" Analog 0 = "); 
    Serial.println(analogRead(A0));  // Example: Read and send Analog pin value to Arduino
    return;  // Done. return to loop();
  }
}

// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{
  switch (pin_num) {
  case 13:
    pinMode(13, OUTPUT);
    digitalWrite(13, pin_value);  
    // add your code here      
    break;
  case 12:
    pinMode(12, OUTPUT);
    digitalWrite(12, pin_value);   
    // add your code here       
    break;
  case 11:
    pinMode(11, OUTPUT);
    digitalWrite(11, pin_value);         
    // add your code here 
    break;
  case 10:
    pinMode(10, OUTPUT);
    digitalWrite(10, pin_value);         
    // add your code here 
    break;
  case 9:
    pinMode(9, OUTPUT);
    digitalWrite(9, pin_value);         
    // add your code here 
    break;
  case 8:
    pinMode(8, OUTPUT);
    digitalWrite(8, pin_value);         
    // add your code here 
    break;
  case 7:
    pinMode(7, OUTPUT);
    digitalWrite(7, pin_value);         
    // add your code here 
    break;
  case 6:
    pinMode(6, OUTPUT);
    digitalWrite(6, pin_value);         
    // add your code here 
    break;
  case 5:
    pinMode(5, OUTPUT);
    digitalWrite(5, pin_value); 
    // add your code here       
    break;
  case 4:
    pinMode(4, OUTPUT);
    digitalWrite(4, pin_value);         
    // add your code here 
    break;
  case 3:
    pinMode(3, OUTPUT);
    digitalWrite(3, pin_value);         
    // add your code here 
    break;
  case 2:
    pinMode(2, OUTPUT);
    digitalWrite(2, pin_value); 
    // add your code here       
    break;      
    // default: 
    // if nothing else matches, do the default
    // default is optional
  } 
}

Did I say too much?

In short, I was able to connect to the HC-05 via bluetooth, I can see that the code is properly sending information from my Arduino sketch to my phone via bluetooth (ArduDroid app), the LED light is wired properly... however it seems I can not send any commands.... the slider bars and toggle button does not turn the LED light on. Any ideas?

I just tried another tutorial (http://www.instructables.com/id/Arduino-AND-Bluetooth-HC-05-Connecting-easily/?ALLSTEPS) and again I am having an issue sending/controlling the LED via Bluetooth (Step 5) using the app SENA BTerm. This is a whole new tutorial, sketch, and android bluetooth app and I can not control anything (Send) to the arduino board via bluetooth HC-05, however I can see i am receiving data through the app on my phone.

Its such a simple connect from the TX on the HC-05 to the RX on the Arduino Uno board… its just one wire. This has me thinking maybe the TX on the HC-05 is shorted out/fried? Is there a way I can test the TX on the HC-05 using a multimeter?

Here is my new code for the above tutorial:

// This program shown how to control arduino from PC Via Bluetooth
// Connect ...
// arduino>>bluetooth
// D11   >>>  Rx
// D10   >>>  Tx
//Written By Mohannad Rawashdeh
//for http://www.genotronex.com/

// you will need arduino 1.0.1 or higher to run this sketch

#include <SoftwareSerial.h>// import the serial library

SoftwareSerial Genotronex(0, 1); // RX, TX
int ledpin=11; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer

void setup() {
  // put your setup code here, to run once:
  Genotronex.begin(9600);
  Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
  pinMode(ledpin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
   if (Genotronex.available()){
BluetoothData=Genotronex.read();
   if(BluetoothData=='1'){   // if number 1 pressed ....
   digitalWrite(ledpin,1);
   Genotronex.println("LED  On D13 ON ! ");
   }
  if (BluetoothData=='0'){// if number 0 pressed ....
  digitalWrite(ledpin,0);
   Genotronex.println("LED  On D13 Off ! ");
  }
}
delay(100);// prepare for next data ...
}

bump

ripcurlksm: This has me thinking maybe the TX on the HC-05 is shorted out/fried? Is there a way I can test the TX on the HC-05 using a multimeter?

A magnifying glass might be the first choice. Somebody has had a solder bridge across the pins of the breakout board, and it was easily fixed.

You might find the following background notes useful

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

Nick_Pyner:

ripcurlksm: This has me thinking maybe the TX on the HC-05 is shorted out/fried? Is there a way I can test the TX on the HC-05 using a multimeter?

A magnifying glass might be the first choice. Somebody has had a solder bridge across the pins of the breakout board, and it was easily fixed.

You might find the following background notes useful

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

Thank you, I read the entire PDF. I tried the code and got the serial monitor in arduino to echo whatever I typed in. However I tried a few android bluetooth apps suggested and couldnt get the serial window to print what i typed in the bluetooth terminal on my phone.

Two questions/observations:

1) One thing I noticed in the PDF is it said that when paired the HC-05 LED will continuously be on. However when I pair to it the LED blinks twice fast and then is off for 2 seconds, then repeats. When I unpair my phone from the bluetooth, the LED blinks very fast continuously. Is this normal or should the LED on the HC-05 be continuously on when paired?

2) When I open a bluetooth terminal on my android, i can see the "GET" data being loaded from the serial window so I know I am able to receive data. It seems my problem is the "SEND" portion where I type a letter or number and it does nothing. I am puzzled because the connection between the HC-05 Tx and Arduino Rx is so simple, its just a wire connecting them... so its not like I messed anything up, right?

Thanks for your comments. I now realise that I should have been clearer in my notes and will edit them soon.

ripcurlksm:
However I tried a few android bluetooth apps suggested and couldnt get the serial window to print what i typed in the bluetooth terminal on my phone.

You are right about this, and having the serial monitor connected while blue tooth is operating is not as useful as I have implied. The real value of using the monitor is in proving up the code before bluetooth is installed.

  1. One thing I noticed in the PDF is it said that when paired the HC-05 LED will continuously be on.

Pairing is a once-only process. Android sniffs for Arduiono and and stoes its address and password. Every time you use an app, you make a connection - by hitting the connect button.

When Bluetooth has power but is waiting for connection, LED flashes about 2Hz. When a connection is made by Android, the LED goes solid. Android also confirms the connection. In normal operation, that is all you should see - 2Hz waiting, solid connected.

However when I pair to it the LED blinks twice fast and then is off for 2 seconds, then repeats

I don’t know what this is about. Somebody else had the same thing only yesterday or the day before.

When I unpair my phone from the bluetooth, the LED blinks very fast continuously.

This is normal, as it has reverted to “wait mode”

  1. When I open a bluetooth terminal on my android, i can see the “GET” data being loaded from the serial window so I know I am able to receive data. It seems my problem is the “SEND” portion where I type a letter or number and it does nothing. I am puzzled because the connection between the HC-05 Tx and Arduino Rx is so simple, its just a wire connecting them… so its not like I messed anything up, right?

See above. I now believe that, once the code is proven, the serial monitor should be out of the game. Note also that the code has no value other than to prove the communication works. Just send a couple of letters, see the echo, and move on to something useful.

I’m sure IO had RealTerm on a laptop showing all the bluetooth traffic but I’m not able to check that at this time.