Checking the Connectivity Status of the HC-05 Bluetooth Module

Hello, I have made a Door lock project using the HC-05 module and an android app. The problem is that sometimes the module disconnects with the phone and the app still tries to send commands to the Arduino. I want the Arduino to check the connection status of the module and the phone at every instance and display the status on the LCD. Please tell me how can I do this. My code is given below:

<
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int y=13,r=10,b=9;
void setup() {
digitalWrite(8, LOW);

digitalWrite(y, HIGH);

lcd.begin(16,2);lcd.setCursor (0,0);lcd.print("Haris Door Lock");
lcd.setCursor (4,1);lcd.print(" LOCKED ");
Serial.begin(9600);
pinMode(8, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()>0)
{
char data= Serial.read();
switch(data)
{
case 'o': digitalWrite(8, HIGH);digitalWrite(y, LOW);digitalWrite(b, HIGH);
lcd.setCursor (4,1);lcd.print("UNLOCKED");
delay(5000);digitalWrite(8, LOW);
lcd.setCursor (4,1);lcd.print(" LOCKED ");
digitalWrite(y, HIGH);digitalWrite(b, LOW);
break;

    case 'c': digitalWrite(8, LOW);
    digitalWrite(y, LOW);digitalWrite(r, HIGH);
     lcd.setCursor (4,1);lcd.print(" SEALED ");delay(120000);
     lcd.setCursor (4,1);lcd.print(" LOCKED ");digitalWrite(r, LOW);digitalWrite(y, HIGH);
     break; 
    default : break;
  }
  Serial.println(data);

}
delay(50);
}
/>

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

When you posted your code without code tags did you receive a warning message ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.