Posts: 1
Joined: Fri Jan 03, 2014 10:08 am

Bluetooth GPIO control

Fri Jan 03, 2014 10:43 am

Hi all!

My wood shed is at the bottom of the garden. Currently i have a motion sensitive light (LED flood light) so i can see down there in the dark, problem is every beastie or gust of wind sets the light off! What i want to achieve is have my pi hooked up to the light via the GPIO and a relay (for the larger power) and for the pi to connect to my phone via bluetooth. I have a small circuit which i have tested with 3.3vdc and it works for switching the larger power on the relay. Im now trying to get the code working on the pi. I need the code to:
1- auto connect via bluetooth
2- once connected;
a) stop bluetooth search
b) set one of the pins (say 14) on the GPIO to HIGH for switching the relay.
3- when i walk away and the RSSI drops to say -10 for the pi to;
a) disconnect the bluetooth and search again
b) set the GPIO pin to low

So now when i walk to the shed it should sense me and turn the light on and when i walk away it should turn the light off. if this works i might add a speaker that tells the spiders and rats to go away when the light comes onto :-)

I have my pi, bluetooth dongle, and my simple tested relay circuit. i have used my pi for a portable bluetooth audio system before so it should have the right bluetooth installation on it but now i have no idea where to start coding it?

If someone could point me in the right direction i would be very grateful!

Posts: 27
Joined: Tue Jul 03, 2012 4:43 pm

Re: Bluetooth GPIO control

Mon Jan 06, 2014 11:18 pm

There is an example how to scan for a Bluetooth device that doesn't need to be discoverable.

I tried it on the RPi and it takes less than a second to find if the device is there, and about 5 seconds if it's not there (or Bluetooth is turned off). Probably that time depends mostly on the Bluetooth dongle, not on the CPU. "top" showed no activity while the "hcitool name ..." was running.

You don't get any RSSI values in this way, though. If the Bluetooth dongle can still see your phone when you are in the house, you could attenuate the dongle "mechanically", by putting it in a metal box or something.

You can also see the RSSI values if you run "bluetoothctl" and enter "scan on" at its prompt (there's also a "help" command). But your phone has to be discoverable for these RSSI values apparently.

Once you have the Bluetooth detection part, you can use the WiringPi gpio utility to switch your GPIO pin.

Return to “General discussion”