help me please about hc 05

please help me :frowning:
.
i have 2 arduino uno and 2 bluetooth hc 05

i have been set a modul (master and sleave)
i want my sleave module can blink led when master modul get a digital input
please help me to write a sketch
.
:frowning:

You can send data over the RX and TX pins on the Arduino. If a pin is HIGH, send "1", if LOW send "0". It should be pretty simple.

Here is some code to do that.
The transmitter:

//Transmitter sketch for HC-05 module
#include <SoftwareSerial.h>
byte RXPIN = 2;//Connect to the RX pin on the Bluetooth module
byte TXPIN = 3;//Connect to the TX pin on the Bluetooth module
SoftwareSerial bluetooth(RXPIN, TXPIN);
byte inputPin = 4;//the pin that is read
void setup() {
  // put your setup code here, to run once:
  bluetooth.begin(9600);
  pinMode(inputPin, INPUT_PULLUP); 
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(inputPin) == LOW) {
    bluetooth.print("0");
  }
  else {
    bluetooth.print("1");
  }
  delay(50);
}

And the receiver:

//Transmitter sketch for HC-05 module
#include <SoftwareSerial.h>
byte RXPIN = 2;//Connect to the RX pin on the Bluetooth module
byte TXPIN = 3;//Connect to the TX pin on the Bluetooth module
SoftwareSerial bluetooth(RXPIN, TXPIN);
byte outputPin = 13;//the onboard LED
void setup() {
  // put your setup code here, to run once:
  bluetooth.begin(9600);
  pinMode(outputPin, OUTPUT); 
}

void loop() {
  // put your main code here, to run repeatedly:
  if (bluetooth.available() > 0){
      int data = bluetooth.read();
      if(data = '1'){
          digitalWrite(outputPin, HIGH);
      } 
       else {
            digitalWrite(outputPin,LOW);
       }
}

If it doesn't work, try changing the baud rate in the 'bluetooth.begin(RATE)' line.
Often, bluetooth modules come configured to 57600 baud.
If no baud rates work, try switching the RX and TX pins on both the transmitter and receiver.

EDIT Fixed the code. Copied wrong.

@Isaac96 you seem to have duplicated the transmitter sketch code. But the OP should know how to tweak the receiver sample sketch according to his needs :wink:

ihave ben set a module (master and sleave)

my problem is my arduino cant work with android after i set modul following step from

.
before i set a module as a master my arduino and android can work with this sketch

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
int ledPin = 5; 
int state = 0;

void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
mySerial.begin(9600);
Serial.begin(9600);
}

void loop() {
 
if(mySerial.available() > 0){
state = mySerial.read();

}

if (state == '1') {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
Serial.println("LED: on");
}
}

but. after i set following step by

my android cant work
.

please help me

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

your suggesttion is good
my arduino now can work
but i have new problem
.
i want to back to previous project
before i set a module (master and sleave)
my arduino can work with android
but
after i set a master and sleave using step by Phillipe Cantin: HC-05 Bluetooth link with zero code
my arduino cant work with android using this sketch

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
int ledPin = 5; 
int state = 0;

void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
mySerial.begin(9600);
Serial.begin(9600);
}

void loop() {
 
if(mySerial.available() > 0){
state = mySerial.read();

}

if (state == '1') {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
Serial.println("LED: on");
}
}

.

whats wrong with my bluetooth?
:confused: :confused: :confused: :confused: :confused:

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

You must have configured that HC-05 for auto connect. I think you now need to return to the default modes by sending AT+RESET

my arduino still cant work
:confused: :confused: :confused:

@maulanaharis, do not cross-post. @maulanaharis, do not cross-post. @maulanaharis, do not cross-post.

Hey,I think you should refer to this article

abhikul22:
Hey,I think you should refer to this article

He is (You are) using an HC-06, but the OP's about an HC-05.
"Same, same"?

maulanaharis:
your suggesttion is good
my arduino now can work
but i have new problem
.
i want to back to previous project
before i set a module (master and sleave)
my arduino can work with android
but
after i set a master and sleave using step by Phillipe Cantin: HC-05 Bluetooth link with zero code
my arduino cant work with android using this sketch

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11);
int ledPin = 5;
int state = 0;

void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
mySerial.begin(9600);
Serial.begin(9600);
}

void loop() {

if(mySerial.available() > 0){
state = mySerial.read();

}

if (state == '1') {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
Serial.println("LED: on");
}
}



.


whats wrong with my bluetooth?
:confused: :confused: :confused: :confused: :confused: 

Moderator edit: 
<mark>```</mark>
<mark>[code]</mark>
<mark>```</mark>

<mark>```</mark>
<mark>[/code]</mark>
<mark>```</mark>
tags added.

Then keep the Bluetooth module in master mode! Actually, I'll bet the problem is the baud rate.