slave code for receving data from master

Hello

My project is when tilt sensor is activated sender side will get power supply and hc-05 bluetooth master bluetooth will turn on and binds with slave. slave side bluetooth will be always on and it will be searching for bluetooth to bind.

i tried to activate the sensor and receiver side i have buzzer it got turned on when tilt sensor got activated. but the problem is buzzer is not turning off when i make tilt sensor off and master bluetooth is off.

can someone please check the code.

#define ledPin 6
int state = 0;
void setup() {
Serial.begin(38400);
pinMode(ledPin, OUTPUT);
digitalWrite (ledPin, LOW);

}
void loop() {

if(Serial.available() > 1){
state = Serial.read();
Serial.write(state);}
else {
Serial.write('0');
digitalWrite(ledPin, LOW);

}
if (state == '1')
{
digitalWrite(ledPin, HIGH);

}
else if (state == '0')
{
digitalWrite(ledPin, LOW);
}
}

I think thats only a bit of your code, and not where the problem lies !

Hello

Thank you for your reply, but when connection is lot with sender here at receiving side output that is buzzer is not going low.

i want three condition

when there is no binding with other bluetooth receiver side should always give 0

when there is binding or input from sender side receiver should give 1