Need some helps with hc05 on my arduino leonardo!

Hi there, I'm really new to arduino stuff

Recently I'm trying the tutorial from here:

and it seems my ArduTooth did connected to the hc05, since the light on hc05 turned from blinking really fast to blinking twice and off one second.

But it still doesn't show any data on my ArduTooth

I also have tried some other easy codes and apps that could control LED on and off, but none of them really work for my android, tho I think it did connect to the hc05. Can anyone show me how to do it? Much thanks.

Can anyone show me how to do it?

On the Android side? Not here.

On the Arduino side? Sure. You go first, though, by posting your code.

PaulS:
On the Android side? Not here.

On the Arduino side? Sure. You go first, though, by posting your code.

#include <SoftwareSerial.h>

SoftwareSerial BTserial(10, 11); // RX | TX

int sensorPin = A0;

int sensorValue = 0;

void setup() {

BTserial.begin(9600); }

void loop() {

sensorValue = analogRead(sensorPin);

//IMPORTANT: The complete String has to be of the Form: 1234,1234,1234,1234;

//(every Value has to be seperated through a comma (’,’) and the message has to

//end with a semikolon (’;’))

BTserial.print(“1234”);

BTserial.print(",");

BTserial.print(“1234.0”);

BTserial.print(",");

BTserial.print(“1234 hPa”);

BTserial.print(",");

BTserial.print(“500 ml/s”);

BTserial.print(",");

BTserial.print(sensorValue);

BTserial.print(";");

//message to the receiving device

delay(20);

}

Here you go.

The Leonardo has two hardware serial ports - the one connected to the 32U4 chip (Serial) and the one connected to pins 0 and 1 (Serial1). Why do you need to use SoftwareSerial?

Where, in that code, are you actually reading anything that the phone sends? Is the phone expecting, somehow, the data that you are sending it?

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

Just use "Serial1." instead of "Serial." and I think you will be OK.

and it seems my ArduTooth did connected to the hc05, since the light on hc05 turned from blinking really fast to blinking twice and off one second.

"Really fast" is normally about two flashes per second and simply signifies power on and ready.

The slower mode, about one flash every two seconds says you are in AT mode. Whatever confusion reigns, the fact that you are seeing two different flash speeds suggests you are, or have been, in AT mode. Stay away from Instructables.

No, in the code, it's not reading anything from my phone sends. The purpose of the code is only to output the data to the phone.

Alright now I removed SoftwareSerial

while (Serial1.available())
{
delay(3);
c = Serial1.read();
readString += c;
}

And i'm sure it can enter the while loop when I input sth on my phone, the thing is that I'm not sure if Serial1 can read data or not, cos I tried entering 1, "If c=='1'" then set the LED high, but it didn't work

DerpityDerpDerpy:
it's not reading anything from my phone sends. The purpose of the code is only to output the data to the phone.

I recognise that English is a second language, but this does not make any sense.
Is HC-05 connected to pins 0,1 in the proper manner?
The code I gave you works both ways. If you only want one way, don't use the other way.

Nick_Pyner:
I recognise that English is a second language, but this does not make any sense.
Is HC-05 connected to pins 0,1 in the proper manner?

Sorry my first language is Chinese :stuck_out_tongue_winking_eye:

And yes, hC-05 connected to pins 0,1.

What I meant was, I can't read the data sent from android, nor can I show the data sent from arduino on my android.

OK. I understand that it doesn’t work in either direction. The notes I posted specifically cover Arduino <> Android. Note particularly that this can be as much a matter of procedure as programming.

  1. Stay away from Instructables.
  2. Get rid of the ArduTooth, and use a standard Bluetooth terminal instead.
  3. Check the notes and use the whole code as given, but be sure to change all Serial commands to Serial1 commands.
  4. Check the wiring.
  5. Stay away from Instructables.
  6. Check the wiring - again.

Since you are using Serial1 to read from the bluetooth device, on the Leonardo, you can use Serial to talk to the PC. So, do that. Learn whether you are even receiving any information.

Does your device have any lights to indicate that it is receiving data?