HC05 to HC05

Hello smart people :slight_smile: ,

I have paired two HC05 together 1 as a master and the other as a slave i have a programming question. I want to push a button from the master arduino to make an LED Turn on on the other slave Arduino.

I the two arduino's are already paired only issue i have is programming issue.

Here is my Master Sketch:

const int ledPin = 42; // choose the pin for the LED
const int inputPin = 46; // choose the input pin (for a pushbutton)
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare pushbutton as input
Serial.begin(38400);
}
void loop(){
int val = digitalRead(inputPin); // read input value
if (val == HIGH) // check if the input is HIGH
{
Serial.write('1');  

}
else
{
Serial.write('0');  
}
}

In the above code i have the switch debounce bug that I could not fix.

Here is the Slave-code:

int LED = 7;
int Recieved;
void setup() {
  // put your setup code here, to run once:
pinMode(LED, OUTPUT);
Serial.begin(38400);
}

void loop() {
  // put your main code here, to run repeatedly:
 if(Serial.available() > 0){ // Checks whether data is comming from the serial port
    Recieved = Serial.read(); // Reads the data from the serial port
 }
if (Recieved = '1')
{
  Serial.println('9');
  digitalWrite(LED,LOW);  
}
if (Recieved = '0')
{
  Serial.println('8');
  digitalWrite(LED,HIGH);  
}

I do not know why it is not receiving data from the master HC-05 even though the two devices are paired. Also I would really appreciate it if anyone can help me solve the switch debounce problem.

Sorry but I don't see where Bluetooth comes into your code.

Hello brother,

The bluetooth is connected through this. I checked on youtube and one Mechatronics channel did this also.

Serial.write('1');

If thats the wrong way to do it, please help :slight_smile:

stowite:
Sorry but I don't see where Bluetooth comes into your code.

And nor should you, it's just a serial connection.

CoffeeBrain:
I do not know why it is not receiving data from the master HC-05 even though the two devices are paired. Also I would really appreciate it if anyone can help me solve the switch debounce problem.

Pairing is not the same as connecting, and there is plenty of room for self-deception here. Check here fore some good information
http://www.martyncurrey.com/connecting-2-arduinos-by-bluetooth-using-a-hc-05-and-a-hc-06-pair-bind-and-link/

Thank you very much Nick_Pyner :slight_smile: Gonna try it out. It looks like it makes more sense than what i wrote hehehe :D.

Thank you.