Please, I am trying to communicate between two arduinos each having HC-05 bluetooth modules. I have been able to make one master and the other slave. I have also been able to pair the two of them and each can recieve byte, but the challenge I have is that the only data that is displayed is "128" no matter what I send, I still receive 128 and sometimes 248. I configured it in such a way that when you press a button on the master, the serial monitor of the slave prints a data that I am sending. I have changed the data type of the received data, and same problem exists. Here is the code for both master and slave. Your help will be appreciated.
//CODE FOR MASTER(SENDER)
#include<SoftwareSerial.h>
const int rxPin = 10;
const int txPin = 11;
const int button = 2;
SoftwareSerial mySerial(rxPin,txPin);//RX,TX.
void setup() {
pinMode(button, INPUT);
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
int buttonVal = digitalRead(button);
if(buttonVal == HIGH){
//mySerial.write("4");
mySerial.println('4');
}
}
[code]
//CODE FOR SLAVE(RECEIVER)[/b]
[code]
#include<SoftwareSerial.h>
const int rxPin = 10;
const int txPin = 11;
SoftwareSerial mySerial(rxPin,txPin);//RX,TX.
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
mySerial.begin(9600);
void loop() {
while(mySerial.available()==0);
digitalWrite(13, HIGH);
int inData = mySerial.read();
delay(1000);
Serial.println(inData);
}
You have mySerial.println('4');
Is that exactly what you have? A numeral four between apostrophes instead of quotes. Is the SoftwareSerial syntax different?
I think you need quote marks --
mySerial.println("4");
I tried mySerial.println("4"); and it still gives me the same thing. But when I pair the HC-05 with my phone it can send and receive data appropriately.
Hi Thank you so much for your effort. The problem persists. what the receiver prints on the serial monitor is 255 every 2 seconds, even when I change the data sent from the transmitter. Though I modified your print syntax so as to get it to display well as shown in the attachment. Here is the modification on the receiver part of the code you sent to me:
Thanks Runaway Pancake, I have been able to resolve the issue. I had to put my bluetooth master module in AT mode and changed the BAUD RATE to 9600 and it started working. This really gave me headache but thank God I resolved it. Thanks for your effort once again. So happy.
Oliver_Arduino:
I probably did not understand this your question ( "Is that thing in 'AT mode'?" )
I guess - it's a question that should be asked, not of you now, but anybody else in the future.
Probably a lot like our biggest dialog around here:
P - "blah, blah, blah...it not work."
R - "Did you connect the Grounds together?"
P - "Well, d'uh, of course I... I thought I did but I didn't - it's working now."
Oliver_Arduino:
However, the steps on how to put HC-05 bluetooth module in AT command mode can be found here:
Oliver_Arduino:
Thanks Runaway Pancake, I have been able to resolve the issue. I had to put my bluetooth master module in AT mode and changed the BAUD RATE to 9600 and it started working. This really gave me headache but thank God I resolved it. Thanks for your effort once again. So happy.
Thank you so much i was having the same problem you solved it so relieved thank you again