Raspberry Pi Bluetooth In/Out Board or "Who's Home"

by prb3333 in Circuits > Raspberry Pi

161653 Views, 148 Favorites, 0 Comments

Raspberry Pi Bluetooth In/Out Board or "Who's Home"

in out board 1.png
I wanted to create an electronic In/Out Board. The type you may have to record who is present or not in a company or home. It is usually placed by the front entrance so anyone can see who is in or out.

I also wanted another project for my Raspberry Pi, so that is why I am using it, but it makes a really good lower power choice of computer to drive this application. There are many extensions to this basic instructable, because of the Pi, like run a web server to show who is in and out via a web page, or run a local LCD display.

There is one major assumption here, that everyone carries a mobile phone and they are willing to keep bluetooth on (is that two assumptions? :-/). Their bluetooth must be on but it is NOT necessary to be 'discoverable' for this to work. Each person must only make there device discoverable for a short time so you can determine their bluetooth address. Once that is found, this device will just query the presence of that known bluetooth device.

I call it my "Who's Home" device.

Raspberry Pi Setup

in out board 2.png
Let's get started.

You will need:
A Raspberry Pi computer, I tested with the 512 MB model, with internet connection.
An SD card loaded with the latest Raspbian “wheezy” software. See http://www.raspberrypi.org/downloads for how to get that setup.
A supported bluetooth USB dongle. See http://elinux.org/RPi_VerifiedPeripherals#USB_Bluetooth_adapters
Some way to access a terminal on the Pi. I used ssh, or just use the normal desktop and open Terminal.


Install Bluetooth Software

in out board 6.png
At the terminal type the command

sudo apt-get install bluez

this will take a little while to install the bluetooth drivers and software.
Also needed is the the pybluez interface from Python to bluetooth.

sudo apt-get install python-bluez

If you have not already, insert your bluetooth dongle into a USB port on the pi.
At the terminal you can use hcitool to check your device, e.g. type

hcitool dev

Get Bluetooth Device Addresses

in out board 4.png
You can use the inquiry.py script from the pybluez website to query the nearby discoverable devices.
https://code.google.com/p/pybluez/source/browse/trunk/examples/simple/inquiry.py

At the pi terminal:
wget https://pybluez.googlecode.com/svn/trunk/examples/simple/inquiry.py
python inquiry.py

You will need the long address, numbers separated by :'s for the next step.


Run the Basic In/Out Board

in out board 5.png
You can get my basic In/Out Board python script using this command:

wget https://raw.github.com/paulbarber/raspi-gpio/master/inoutboard.py

Insert your device addresses and person names into the script. Repeat the 'if' block for each person.
Run it with:

python inoutboard.py

Note that the devices no longer need to be discoverable for bluetooth.lookup_name to work.
Play and make it better!