Is it possible to write code to have the board perform an action when a Bluetooth device it is connected to falls out of range? For example, say I have my phone tethered to a board with a motor to turn a lock. Is it possible to have the board send a message to the motor to turn the when I drive off in the mornings and my phone is disconnected because it falls out of range?
I've read up on Arduino, but I'm not too familiar with the system. I'm trying to figure out if this is the right direction to go for a project, so any help would be appreciated.
HazardsMind, thanks for the code - it's much more than what I was hoping to get! I do have one concern with it though - I may be missing something, but won't that continuously run the action while disconnected? I'm hoping to have it run one time at initial disconnect, not be something it continues to run based on connection status. So the trigger would be a status change, not the status itself. Following with my previous example, it would turn one time when the phone is disconnected, not continue to try to turn the lock when disconnected. And it would turn the lock the other direction when the phone is reconnected.
No need to go through the trouble of rewriting the code or anything - I'm just hoping to clarify. And thanks again!
Yes, there is nothing stopping it from continuously showing "not connected" so you need to check the current state and compare it to a previous state. If the current state is different than the previous state, update the previous state and show the the connection status, otherwise don't show it.