BT presence triggered Door Lock

Hello, I want to built BT presence triggered door lock. I am stuck on coding section.

I can scan nearby bt devices. If a known mac address device is in the range, I want to trigger a relay.

How can I code this ?

if(BTSerial.available())
Serial.write(BTSerial.read());

With thie code, I can see MAC addresses on serial monitor. But I dont know which code to use after.

Start by posting your full sketch using code tags when you do

If you can see MAC addresses in the Serial monitor then you can save them to a variable in order to compare them with know addresses

UKHeliBob:
Start by posting your full sketch using code tags when you do

If you can see MAC addresses in the Serial monitor then you can save them to a variable in order to compare them with know addresses

I could put HC-05 to sniffing mode. On serial monitor I can see MAC addresses of nearby devices with this sketch. I know I should use that MAC address on an if statement, but I dont know exact code.

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10,11); //rx,tx
void setup() {
Serial.begin(9600);

BTSerial.begin(57600);

}

void loop()
{
if(BTSerial.available())
Serial.write(BTSerial.read());

if(Serial.available())
BTSerial.write(Serial.read());

}

What does your serial data look like? How are the MAC addresses separated?

This is serial data. I know "Y"'s are the signal strenght etc... "X"' s are the MAC address. I verified MAC address is correct.

+INQ:XXXX:XX:XXXXXX,YYYYYY,YYYY

Does each line start with a + and end with a carriage return ?

If so, then take a look at Serial input basics - updated and use the delimiters as start and end markers to save the whole line in a zero terminated array of chars

Once a line is complete and stored you can parse it to extract the MAC address and compare it with your targets. The thread linked to has an example of parsing a data string

Yes, each line start like this.

+INQ:XXX
+INQ:XXX
+INQ:XXX
+INQ:XXX
+INQ:XXX
...

Thanks. I will read the thread.