likith sai
likith sai

Reputation: 547

Prints integer value, Arduino HC-05 Bluetooth module

I have a problem which I have been working on for some time. I have an Arduino Uno board and an HC-05 Bluetooth transceiver with TTL outputs.

The connections are as follows:

RX (HC_05)  --> TX (Arduino UNO)

TX (HC_05)  --> RX (Arduino UNO)

GND (HC-05) --> GND (Arduino UNO)

+5V (HC-05) --> +5V (Arduino UNO)

I have the following Arduino code:

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX

void setup()
{
  Serial.begin(9600);
  BTSerial.begin(38400);  // HC-05 default speed in AT command more
  pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
  pinMode(10, INPUT);
  pinMode(11, OUTPUT);
  
  digitalWrite(9, HIGH);
  Serial.println("Enter AT commands:");
  BTSerial.println("Welcome to ARBA-Beat");
}


void loop()
{

  // Keep reading from HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available()) {
    Serial.println(BTSerial.read());
    BTSerial.write(BTSerial.read());
    BTSerial.flush();
  }      
}

I connect to the Bluetooth module through the Bluetooth Terminal Android app. Everything works fine (even the lights on the Bluetooth module). But when I send a character from the phone to Arduino, I get the following output:

Text sent to Bluetooth module - a

enter image description here

please help

thank you

Upvotes: 1

Views: 1492

Answers (1)

Joshua Hrisko
Joshua Hrisko

Reputation: 11

I had the exact same issue. Have you tried running the HC-05 at 9600? Try the code below (with your pins). I used the code to switch a relay on pin 2, but you could use an LED if you want. I used the same Bluetooth app and it worked fine:

#include <SoftwareSerial.h>
int relay = 2; // Set pin for relay control

SoftwareSerial bleserial(8,9);

// setup the relay output and the bluetooth serial, and the serial monitor (if you want to print the outputs)
void setup() {                
  // set relay pin as output.
  pinMode(relay, OUTPUT); 
  // start bluetooth and serial monitor  
  bleserial.begin(9600);
  Serial.begin(9600);

}

void loop() {

  if(bleserial.available()){

    char char1 = bleserial.read();
    Serial.println(char1);
    // Set protocol that you want to turn on the light bulb, I chose 1 and 0 as on and off, respectively

    if(char1=='1'){
      Serial.println("ON");
      digitalWrite(relay,LOW);
    } else if (char1=='0'){
      digitalWrite(relay,HIGH);
    }
  }

}

If you want to see wiring etc. check out the entry on my blog:

https://engineersportal.com/blog/2017/11/15/bluetooth-home-automation-light-bulb-switch-using-an-hc-05-a-relay-and-arduino

Upvotes: 0

Related Questions