Arduino end switch doesn't react with bluetooth module

Hello,

For some time now i am trying to make a smart door lock, but i have some problems with the sketch. I am using a HM10 for the bluetooth connection and 2 end switches for the detection of the key inside the lock. I have wired a 10k ressistor between the swtiches and the arduino. I have made a simple sketch for the Arduino. The problem is that the lock isn't reliable, the bluetooth part is working but when i send something by bluetooth and after that i press one of the end switches it is supposed to go to a angle but the motor doesn't react on the switches. When i erase the bluetooth part in the sketch and i upload only the switch part it works but when it is combined the lock doesn't react on the switches anymore.
This is the sketch that i made:

#include <Servo.h>

const int buttonPin = 2;   
const int buttonPin1 = 7;   
int buttonState = 0;      
Servo servo;
int tx=1;
int rx=0;
char inSerial[15];

void setup() {
  Serial.begin(9600);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin, INPUT);
  pinMode(tx, OUTPUT);
  pinMode(rx, INPUT);
  servo.attach(13);
}

void loop() {
     int i=0;
    int m=0;
    delay(500);                                         
    if (Serial.available() > 0) {             
       while (Serial.available() > 0) {
         inSerial[i]=Serial.read(); 
         i++;      
       }
       inSerial[i]='\0';
      Check_Protocol(inSerial);
     }
     
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    servo.write(0);
  } 
    buttonState = digitalRead(buttonPin1);
  if (buttonState == HIGH) {
    servo.write(120);
  } 
}
void Check_Protocol(char inStr[]){   
  int i=0;
  int m=0;
  Serial.println(inStr);
   
   if(!strcmp(inStr,"open")){    
    servo.write(0);
    Serial.println("Servo 0");
    for(m=0;m<11;m++){
      inStr[m]=0;}
       i=0;}

   if(!strcmp(inStr,"close")){   
    servo.write(120); 
    Serial.println("Servo 120");
    for(m=0;m<11;m++){
      inStr[m]=0;}
       i=0;}
       
    else{
    for(m=0;m<11;m++){
      inStr[m]=0;
    }
    i=0;

}}

What has to be changed to let it work with the bluetooth module and the switches?

What is the variable "i" doing in "Check_Protocol"?

You seem to be updating the servo in your checkProtocol() function and in loop() so the updates are probably clashing.

Create a simple function to update the servo based on the value in a variable and call that function as the last thing in loop(). And make sure that that function is the only place in the program where the servo position is updated.

Then in the rest of your code you can update the position variable depending on the button input or the Serial input.

If things aren't working properly you can print the value of the variable so you can see what is happening.

...R

const int buttonPin = 2;   
const int buttonPin1 = 7;

These are dumb names. There was some reason for adding two switches. The variable names should reflect that.

const int openedPin = 2;
const int closedPin = 7;

Or whatever the two pins are supposed to mean.

   delay(500);

On EVERY pass through loop()? Why?

   for(m=0;m<11;m++){
      inStr[m]=0;}

You clearly do not understand the significance of NULL-terminated in the definition of a string. It takes ONE NULL to terminate a string, not 12. I can't figure out why you write 12 NULLs to a 15 element array, in any case.

You also do not appear to understand that serial data, whether from a GPS, a PC, or a bluetooth device arrives slowly. loop() might iterate several thousand times while "open" arrives. Well, it would without the stupid delay() in it.

Suppose that you send "open" to the Arduino, and "op" arrives while the Arduino has it's head in the sand. You read all the data, and see that it is not "open" and that it is not "closed". So, you NULL out the string.

Then, head back in the sand. Then read "en". That's not "open" and it's not "closed", so you do nothing.

Clearly, sending "open!" or "closed!", and reading and storing data until the '!' arrives, and then calling the function to evaluate the serial data would be a better idea.