dont know how to use bluetooth module hc-05

Status
Not open for further replies.
Serial.begin(9600) too slow if you never used it before
setup is The HC05 module enters the Command mode with Baud Rate 38400.
 
how i can mesure time betven for example 2 clivks of a push botton
becuse i want to make speedometer foe my bike and whit bluetooth send data to my mobile phone
 
This code you can try
Code:
#define rxPin 2
#define txPin 3
#define ledPin 7
#include <SoftwareSerial.h>
SoftwareSerial mySerial(rxPin, txPin);
int state = 0;
void setup() {
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  mySerial.begin(38400); // Default communication rate of the Bluetooth module
}
void loop() {
  if(mySerial.available() > 0){ // Checks whether data is comming from the serial port
    state = mySerial.read(); // Reads the data from the serial port
 }
 if (state == '0') {
  digitalWrite(ledPin, LOW); // Turn LED OFF
  mySerial.println("LED: OFF"); // Send back, to the phone, the String "LED: ON"
  state = 0;
 }
 else if (state == '1') {
  digitalWrite(ledPin, HIGH);
  mySerial.println("LED: ON");;
  state = 0;
 }
}

This should work with post #26
 
Last edited:
After seeing be80be's posts I realise that there musts be more than one version of the HC-05. All the HC-05s I have require a 3.3 volts supply. The ones that be80be shows have a 5 volt supply. Make sure you use the correct data sheet for the version that you have.

Les.
 
Hi be80be,
I have not bought any HC-05s since 2014 so maybe since then more versions of the board have appeared.

Les.
 
i first connected fx-fx and rx-rx and i didnd get nothing then i connected rx-tx and tx-rx and i dond get words i only get numbers.
so when i say hi on my serial monitor it says :
16
16
104
105
13
10
i puted my serial monitor on both nl & cr and i tried more bauds.
i used this program
void setup() {
Serial.begin(38400); // im not sure for this
}
void loop() {
if(Serial.available() > 0){
Serial.println(Serial.read());
}
}
 
i coonected android to bluetooth and litle led stil blinks .while it is not conneced it blinks every second but when i connect it i blinks two times and than it stays off for two seconds
 
You are seeing the ASCII values of the characters you are sending

Decimal Hex Character
16 0x10 DLE (Data link escape I don't know why this character is sent.)
16 0x10 DLE (Data link escape I don't know why this character is sent.)
104 0x68 h
105 0x69 i
13 0x0D C/R (carriage return. Moves curser to left hand side of screen.)
10 0x0A L/F (Line feed. Moves cursur down one line.)

As I said in a previous post I know very little about "C" programming but I THINK the received value is treated as a different data type. I think you may have to use a header file like termios.h to input the data as a string. I spent a few weeks trying to get termios to work the way I wanted on a Paspberry Pi computer.
Edit. I have just read your post #34. You will need to read the data sheet on the HC-05 to find the meaning of the flashing on the LEDs.
Les.
 
I THINK you would have to make a variable (We will call the variable A) equal Serial.read then println (%A) I think the data type for A would be char.
If you had used the method I suggested of removing the MEGA328 then you would see the output as you expected. (For that method the way you originally connected Tx to tx and rx to rx would have been correct.)

Les.
 
i uploaded this program normaly
void setup() {
Serial.begin(38400);
}
void loop() {
if(Serial.available() > 0){
Serial.println(Serial.read());
}
}
whit this connection
and it send ascii code
 
Mine are 4 years old hard to make video with cam in one hand but this is the code i postes and you hook it up and send a 1 for on and 0 for off .
There is to rates for these 38400 and 9600 you may have to change the mySerial.begin(9600); .
If you hook it up like post 26 just like that it works just like the video
 
Your post in 38 will not work with the arduino because your using the same serial port that the atmega uses you just echoing text that way you don't no where it's coming from the hc05 or the atmega
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…