I have an arduino Mega and Uno, and a bluetooth module HC-05,
I connected my arduino to the module in 5V power supply,
I have logged in:
the RX pin on pin TX1 of my arduino,
the pin TX to the pin RX1 of my arduino,
the VCC pin on the 5V pin.
the GND pin to the Power GND pin.
So when I power, my arduino to my computer bluetooth module flashes quickly,
From there, I connect to the Bluetooth module with my phone,
Subsequently I downloaded the application "Bluetooth terminal" to send the number "10" to the bluetooth module
Well, you have told us carefully what you have done, but it appears that you have forgotten to upload any code into the Mega, so I guess it's no surprise that the console said "⸮".
the pin TX to the pin RX1 of my arduino
It is good practice to do this via a 1k/2k voltage divider, but this is probably not the cause of the problem.
char c;
String messageRecu;
void setup() {
Serial.begin(9600);
Serial1.begin(9600); //liaison bluetooth
}
void loop()
{
while ( Serial1.available()>0)//lecture buffer si reçu commande en bluetooth
{
delay(3);
c = Serial1.read();
messageRecu += c;
Serial.print("message Recu sur Serial1 ");Serial.print(messageRecu);Serial.print(" et dernier C recu ");Serial.println(c);
}
messageRecu="";
}
There is NOTHING in your code that prints a single character. If you are not seeing any of the constant strings you are printing, then the problem has nothing to do with the bluetooth device.
You need to be certain that the Arduino and the bluetooth device are communicating at 9600 baud (I have my doubts). You have to be certain that the Arduino and the Serial Monitor app are communicating at 9600 baud (and then have your head examined for using such a low speed).
if your only problem was that your getting ? as the message below:
message Rmessage Recu sur Serial1 ⸮ et dernier C recu ⸮
Then change char c; to int c; , this will take care of the ? sign and you should see numbers instead of question marks as in above line.
Do not use delay(3);. Because when you use delay it will mess up with your received data. The Arduino stops receiving some bits. It is better to remove the delay(3); you donot want any delay when you use bluetooth.
If your problem was that you do not see anything in the serial monitor. Then your problem is with this line:
while ( Serial1.available()>0)//lecture buffer si reçu commande en bluetooth
Because when i removed that line. Stuff starts to appear in the serial monitor.
I had a bluetooth app that i built and was testing your code using it. The app sends random numbers of bits to the HC-05. I noticed that at one time i sent a random sequence of numbers and i got the below message:
message Rmessage Recu sur Serial1 0 et dernier C recu 0
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
Serial1.print(inByte, BYTE);
}
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.print(inByte, BYTE);
}
}
This code is a good example. I see that it is similar to what your trying to do.
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}