0
votes

i cannot understand, when i trying to configure and connect bluetooth with my android device. (i used bluetooth HC-05 from lc-technology and Arduino Mega 2560) I’m trying to connect the arduino and android with bluetooth but it failed. This is a code for arduino

char incomingByte;  
int LED = 12;

void setup (){
    pinMode(LED, OUTPUT);
    Serial.begin(9600);
}
void loop(){
    if (Serial.available()){
        incomingByte = Serial.read();
        if(incomingByte == '1'){
            digitalWrite(LED, LOW);
        }
        if(incomingByte == '0'){
            digitalWrite(LED, HIGH);
        }
    }
}

I try to send data from bluetooth device (i use Bluetooth Terminal and BlueTerm) to Bluetooth Arduino and never give a response i've been trying to uses another pin for tx & rx on Arduino Mega 2560, but it never give a response.

Does someone have a solution on that problem ? Thanks before for your help. I'll apreciate you for your help.

2

2 Answers

1
votes

The software you provided is working. I had exactly the same problem as you reported, with Arduino Uno and the Bluetooth module from the same maker. After many test I came to the following conclusion: the problem is in the Bluetooth module itself cause it doesn't properly manage the tension levels of the TX pin. You don't see any response cause Arduino can not handle the tension levels from the bluetooth module. You find more informations about my tests at the following link: Arduino Forum

A picture of the tension levels of an HC-05 Bluetooth device Tx pin (from 3.1 down to 0 Volt) Tension levels of HC-05 Bluetooth device Tx pin

In the next picture the tension levels of the HC-05 Bluetooth device Tx pin of the maker you and me have used (from 3.3 down to 1.7 Volt), note that the signal can't go down to 0 Volt enter image description here

1
votes

Check the following things:

  1. If you are trying to light up external LED at pin 12 then it is OK. But in case you are trying to light up the on-board LED, it is pin 13.
  2. Check the baud rate you are using in the device to send data. It must be same as the one used in the code.
  3. The HC-05 can operate in a wide range of baud rate (check Google). By default it's programmed to 9600. If somehow yours is different, you'll have to reprogram it (again check Google to see how).
  4. It's irrelevant to say this but 1 represents logic HIGH and 0 represents logic LOW. Although it's up to you to program the way you want, but still it's best to follow the convention to avoid confusion.