HC-05 stops communicating after 3 minutes

Hi,
I am using an Arduino Uno and Nano and 2 hardcoded hc-05’s bluetooth(master and slave that only connect to each other) - in order to turn on a led(connected to the slave) through a button(connected to the master). The rate is 38400 for both.
It works perfectly when starting or when sending data once in a while, but when leaving the system idle after about 3 minutes, it stops working - you can see the data being sent and hc-05 blinking correctly.
When reconnecting one of the Arduinos everything works again as usual.
Any ideas? Mabye some buffer needs to be cleaned?
The master code:

int ledPin = 6;
int data=0;
int button = 8;
int buttonState = 0;

void setup() {
Serial.begin(38400);
pinMode(ledPin, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0)
{
data = Serial.read();
}

buttonState = digitalRead(button);
if (buttonState == HIGH) {
Serial.write(‘1’); // Sends ‘1’ to the slave to turn on LED
digitalWrite(ledPin, HIGH); // LED ON
delay(300);
}
else {
Serial.write(‘0’);
digitalWrite(ledPin, LOW); // LED OFF

}
}

The slave code:

int ledPin = 4;
int data=0;

void setup() {
Serial.begin(38400);
pinMode(ledPin, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0)
{
data = Serial.read();
}
Serial.println(data);
// Controlling the LED
if (data == ‘1’) {
digitalWrite(ledPin, HIGH); // LED ON
delay(300);
}
else if (data == ‘0’) {
digitalWrite(ledPin, LOW); // LED OFF
}
}

Thanks :slight_smile:

BTHC05_master.ino (957 Bytes)

BTHC05_slave.ino (452 Bytes)