Hi everyone!
First of all, I've done projects with HC-05 but i guess i've missed one thing this time.
I used the following code for test my procedure.
` #include <SoftwareSerial.h>
SoftwareSerial MyBlue(19, 18); // RX | TX
Arduino MEGA.
10 and 5 K ohm voltage divider.
2 blinks every 5 S.
It clearly tests "send and receive" via serial monitor. Unfortunately, I don't see anything (even blinking of my rx led on MEGA board) when i send an integer from my phone (I used two different Apps). Sending from board to phone is OK. I've tested two HC-05. what do you think?
if you are using an Arduino mega why not use hardware serial on pins 18 and 19
some sample code I used to test a HC-05
// HC-05 Bluetooth module AT commands
// note Serial1 baudrate is 9600
// using Arduino Due (not HC-05 Rx and Tx are 3.3V
// Arduino %V and GND to HC-05 5V and GND
// Arduino pin 18 Tx to HC-05 Rx
// Arduino pin 19 Rx to HC-05 Tx
void setup()
{
Serial.begin(115200 );
Serial.println("Enter AT commands:");
Serial1.begin(9600);//38400); // HC-05 default speed in AT command more
}
void loop()
{
if ( Serial1.available()) // read from HC-05 and send to Arduino Serial Monitor
Serial.write( Serial1.read());
if (Serial.available()) // Keep reading from Arduino Serial Monitor and send to HC-05
Serial1.write(Serial.read());
}
1. DPin-18, 19 are already assigned to the hardware UART Port (Serial1) of MEGA. So, there is no need to use them as Software UART Port. Your sketch is revised as follows which you may try.
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
Serial.println("Ready to connect\nDefualt password is 1234 or 000");
}
void loop()
{
if (Serial1.available())
{
Serial.println(Serial1.parseInt());
}
if (Serial.available())
{
Serial1.println(Serial.parseInt());
}
}
2. Also check that your HC-05 is connected with MEGA as per following diagram (Fig-1).
Figure-1:
as @GolamMostafa pointed out the HC-05 uses 3.3V logic
I remember I used an Arduino Due (uses 3.3V logic) to test using the code of post #2
if using a Mega you require a level converter on the Mega Tx pin or you may damage the HC-05
Uno has one hardware serial port, Mega has four. Using software serial is never a great idea on a Uno, but sometimes unavoidable. It is a really dumb idea on a Mega. Using software serial on hardware serial pins is simply inviting trouble, but you will not have done any permanent damage.
Defining the hardware serial pins is indeed unnecessary, in fact there is no means of doing that, you just tell the relevant port to "begin".