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();
}
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
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.
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.
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
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.
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.