HC-06 doesn't send data

hi i am trying to communicate between my arduino via bluetooth hc-06 to my computer.

i can send data from my computer/android to the arduino but from some reason i cannot send data from my arduino to the computer.
in addition when i am trying to use the AT commands i can see that they are working but i dont get the ok when i am trying "AT".

someone can help me please? thanks.

this is my code:

// Do not remove the include below
#include "arduinoProjectSample.h"
#include <SoftwareSerial.h>
#include "Bluetooth.h"
#include "dataBase.h"

#define rxPin 8
#define txPin 7

/bluetooth connection variables/
SoftwareSerial blue_ss(txPin, rxPin); //tx and rx are oppsite to the func signture
BLUETOOTH bt(&blue_ss);

/init database/
dataBase DB;

/sending variables/
char myChar ;

void setup() {
/open the computer communication/
Serial.begin(9600);
bt.start();
}

void loop() {
delay(1000);
blue_ss.flush();
String msg = (String)bt.read();
Serial.println("msg = "+msg);
if(msg.length()>1) {
for(int idx=0;idx<ARRAY_SIZE;idx++)
{
DB.samplePorts(idx);
Serial.println(idx);
DB.printDB(idx,bt);
}
}
//DB.printDB(idx,bt);
while (bt.available()) {
myChar = bt.read();
Serial.print(myChar);
}
}

I believe your code is utter junk from beginning to end, and the admonition

// Do not remove the include below

is about the worst advice you will ever receive. It is just possible that this is because the code is extremely ancient, but using it can't be a good idea.

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

tgreenshtein:
when i am trying to use the AT commands i can see that they are working but i dont get the ok when i am trying "AT".

This sounds like nonsense. The bare "AT" command should get an "OK" just like all the other AT commands. You might clarify what "i can see that they are working" really means.

Hi, I have the same issue. Have you solved it?

Eduardo

inglez:
Hi, I have the same issue. Have you solved it?

Eduardo

The OP is 1 and done. LOL.

.

Sorry, didn't get it. What OP is?

OP = original poster = the person who wrote the question

Let us assume that the communication link is: Android Smart Phone - HC06 - UNO - Serial Monitor. Messages will be exchanged between Android Smart Phone and the Serial Monitor. The procedures are:

1. Make the following connection between the HC06 and UNO.

2. Upload the following codes.

#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
// Connect the HC-06 TX to Arduino pin 2(as RX). 
// Connect the HC-06 RX to Arduino pin 3 (as TX) through a voltage divider.
 
char c = ' '; //initializes to a space
 
void setup() 
{
    Serial.begin(9600);
    Serial.println("Arduino is ready");
 
    // HC-05 default serial speed for communication mode is 9600
    BTserial.begin(9600);  
    Serial.println("BTserial started at 9600");
}
 
void loop()
{
   // Keep reading from HC-05 and send to Arduino Serial Monitor


    if (BTserial.available())
    {  
        c = BTserial.read();
        Serial.write(c);
    }
 
   // Keep reading from Arduino Serial Monitor and send to HC-06
    if (Serial.available())
    {
        c =  Serial.read();
 
        // Copy the serial data back to to the serial monitor. 
        // This makes it easy to follow the commands and replies
        Serial.write(c);
        BTserial.write(c);  
    }
 
}

3. Bring in the Serial Monitor.

4. Pair the Bluetooth Terminal (BTT) of Android with HC06.

5. Type Hello! at BTT and press send button

6. Check that the message has apperaed on the Serial Monitor.

7. In the InputBox of Serial Monitor, enter OK! and press send button.

8. Check that the message has appeared on BTT.

I had to look up the "1 and done" part. Our terminology would be "one night stand".

Don

floresta:
I had to look up the "1 and done" part. Our terminology would be "one night stand".

Don

1 and done is in reference to the NCAA men's basketball rule
where the player must play at least 1 year to be eligible to play in the NBA
:slight_smile:

inglez:
Hi, I have the same issue.

The issue as stated was so nonsensical that you probably don't, and you may never find out what happened anyway. One thing you can be absolutely certain of is that bluetooth is a lot simpler the the original post implies, and that code appears to be written just put people off.

I don't think the original actually did, but IF you have communications code already working, there may be no need to change it - just connect bluetooth and go. Either way, 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

And note that you can get going without any AT commands!

I have problem, I can pair my smartphone with the Bluetooth Hc06 but I send commands to turn ON or OFF the LED

this is my code

int led = 13;
char data;
void setup()

{
pinMode(led, OUTPUT);
Serial.begin(9600);

}
void loop()
{
while (Serial.available()> 0)
{
data = Serial.read();

}
if(data == '1')
{
digitalWrite(led, HIGH);
Serial.println("LIGHT ON");

}

else if(data == '0')
{
digitalWrite(led, LOW);
Serial.println("LIGHT OFF");

}

}

I have problem, I can pair my smartphone with the Bluetooth Hc06 but I can't send commands to turn ON or OFF the LED with the smart phone.

this is my code

int led = 13;
char data;
void setup()

{
pinMode(led, OUTPUT);
Serial.begin(9600);

}
void loop()
{
while (Serial.available()> 0)
{
data = Serial.read();

}
if(data == '1')
{
digitalWrite(led, HIGH);
Serial.println("LIGHT ON");

}

else if(data == '0')
{
digitalWrite(led, LOW);
Serial.println("LIGHT OFF");

}

}

1. Connect UNO/NANO and HC06 as per following diagram. DPin-2 of UNO/NANO ---> TX of HC06; DPin-3 of UNO/NANO ---> RX of HC06 via divider circuit; GND of UNO/NANO ---> GND of HC06. Do not connect any device/component with DPin-0 and DPin-1 as they are connected with Serial Monitor/IDE for debugging/uploading.

2. Upload the following sketch which is a slight modified version of your one.

#include<SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //SRX = DPin-2 pf UNO; STX=DPin-3

int led = 13;
char data;

void setup()
{
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  mySerial.begin(9600);
  digitalWrite(led, LOW);   //LED is OFF iniially
}

void loop()
{
  byte n = mySerial.available();
  if ( n != 0)
  {
    data = mySerial.read();
    if (data == '1')
    {
      digitalWrite(led, HIGH);
      Serial.println("LIGHT ON");   //message comes on Serial Monitor of UNO/NANO
    }
    else
    { if (data == '0')
      {
        digitalWrite(led, LOW);
        Serial.println("LIGHT OFF");
      }
    }
  }
}

3. Pair Android and BT of UNO/NANO.

4. Send 1 in ASCII Mode from Android. Check that L (built-in LED of UNO/NANO) of UNO/NANO is ON.

5. Send 0 in ASCII Mode from Android. Check that L is OFF.

Coffie:
I have problem, I can pair my smartphone with the Bluetooth Hc06 but I can't send commands to turn ON or OFF the LED with the smart phone.

Pairing only proves that there is communication between the phone and Bluetooth. It does not mean that there is proper connection between Bluetooth and Arduino. The code looks pretty right and, if you got it from somewhere sensible, it probably is. Since you are using Hardware serial, you can prove the code is kosher by using the serial monitor to send the commands first, rather than bluetooth. Your problem may simply be the wiring. Make sure that it is Rx>Tx and Tx>Rx.