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

142,566

139

38

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

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.

Step 1: Raspberry Pi Setup

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.


Step 2: Install Bluetooth Software

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

Step 3: Get Bluetooth Device Addresses

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.


Step 4: Run the Basic In/Out Board

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!

Share

    Recommendations

    • Audio Contest 2018

      Audio Contest 2018
    • Tiny Home Contest

      Tiny Home Contest
    • Furniture Contest 2018

      Furniture Contest 2018

    38 Discussions

    0
    None
    RezaA84

    6 months ago

    pardon me sir, but i have this school project which is similar to ''who's home'' project of yours. the point of my project is the raspberry pi should push the data of any mac address from result ''python inquiry.py'' to mysql database every 1 hour. any raw suggestion how can i do that? (p.s. already configure the database)

    0
    None
    dconsuegra

    9 months ago

    I'll be sure to use this in the next couple of days... Probably using the Bluetooth route.... but I'd like to be able to send the "Daniel is home/has left" command to Smartthings.... Any ideas? Thanks!

    0
    None
    ShaneH26

    1 year ago

    Error 404: file not found.... please advise. https://code.google.com/p/pybluez/source/browse/trunk/examples/simple/inquiry.py

    1 reply
    0
    None
    prb3333ShaneH26

    Reply 1 year ago

    It appears to have moved to:
    https://github.com/karulis/pybluez/blob/master/examples/simple/inquiry.py

    Cheers,
    Paul

    0
    None
    KeoO

    1 year ago

    I have a Raspberry Pi 3 so now bluetooth is standard with the device. There are also built in functions. Run "hcitool scan" to scan for discoverable bluetooth devices. I am going to re-write the code to pull a user list from a JSON config file. To run bluetooth and wifi, add both sets of credentials to each user.

    1 reply
    0
    None
    HydrostevoKeoO

    Reply 1 year ago

    Cool, I would be interested to see what you get. I am looking for a solution using BLE beacons instead of smart phones running on Raspberry Pi 3 with Jessie.

    0
    None
    wv110

    3 years ago on Introduction

    I'd like to build this inside my car. Then when I approach the car it unlocks. When I leave it locks. Getting tired of fob not working...Any comments?

    2 replies
    0
    None
    JasonR238wv110

    Reply 1 year ago

    I'm working on this right now, but instead of wiring it directly to the door locks and all that extra work, I'm just disconnecting the battery ground in my key fob and running the wires to the relay controlled from the pi (one wire from the negative of the battery and the other wire back to the ground of the key fob). So the key fob becomes powered again when phone is in range. I will probably wire it so that it sends a lock command when out of range because it won't let me lock the car with the key fob powered and inside the car. Or use a manual input to shut off the key fob when the car stops running so then the car can be locked as you get out as well.

    0
    None
    cchiosawv110

    Reply 2 years ago on Introduction

    It could be a potential problem regarding security... the long addresses are spoofable. But then again, who is going to know that you are scanning for bluetooth in the area?

    Also, you'll have to tangle the beast that is car security systems.

    But if you do manage, let us know how you did it! Good luck!

    0
    None
    CesarD17

    2 years ago

    Hi,

    I like this script, but i don´t get that inquiry.py work on mi RasperyPi2, this is the error message when i type "python inquiry.py":

    performing inquiry...

    Traceback (most recent call last):

    File "inquiry.py", line 12, in <module>

    nearby_devices = bluetooth.discover_devices(duration=8, lookup_names=True, flush_cache=True, lookup_class=False)

    TypeError: discover_devices() got an unexpected keyword argument 'lookup_class'

    Thanks you for your help.

    2 replies
    0
    None
    RomanS59CesarD17

    Reply 1 year ago

    I was able to get it to work by manually removing the ", lookup_class=False" part. According to https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=159442 it's deprecated?

    0
    None
    moldakerCesarD17

    Reply 2 years ago

    The script still works, I was getting the same error, make sure that Bluetooth is set up on the Pi, and the device is paired and trusted before running the script.

    0
    None
    DS56

    2 years ago

    I am a nube to python and programming, but have a project in mind this will help me with.

    This Works pretty good and i'm very interested in getting this to work for me, however, I noticed that as long as John is found, then it "looks" for Paul, then Paul shows either In or Out correctly, but if John is not found, it assumes Paul is not found and does not try to "look" for Paul, and just prints

    John: Out

    Paul: Out

    If i comment out John's section, then the Paul's works as expected.

    Please Help. Thanks

    1 reply
    0
    None
    prb3333DS56

    Reply 2 years ago

    Hi,
    Is it an issue with the line indentation?
    Python is fussy about how specific lines are indented to make the 'if' statements work correctly. If your indentation is with spaces, check all the indents have the same number of spaces.
    Hope that helps,
    Paul.

    0
    None
    PranveshC

    2 years ago

    unable to get inquiry.py code from https://code.google.com/p/pybluez/source/browse/trunk/examples/simple/inquiry.py and https://raw.githubusercontent.com/karulis/pybluez/master/examples/simple/inquiry.py

    0
    None
    BudByrd

    2 years ago

    Nice script. Added GPIO commands to run status LEDs.

    0
    None
    DanielW166

    2 years ago

    Hi all,

    I'm not a programmer nor do I own a Raspberry Pi, but looking at this gave me an idea and I was wondering if it's feasible so need your help:-

    I work in a primary school and thought that for the safety of the children how accurate would it be if they wore some kind of bluetooth tag, or wifi tag, to indicate where they were? If there were Pis placed around the building, and the nearest Pi with the strongest signal picked up a kid's tag -- would that work?

    Could this go anywhere?

    Im aware these kind of systems exist in hospitals in the UK but use different sensors and such -- can it be done using rasperry pi? If so, how accurately?

    0
    None
    jwarren20

    2 years ago

    Nice project however I don't think Bluetooth is the best way to do this function due to it's limited range.

    A much better way is to use the WiFi connection that already in place, the Pi doesn't need WiFi it's self, and detect the MAC address of the connecting phone. This has the advantage of much larger range than you could ever get using Bluetooth. There is also not any limitation other then the number if devices the local network can handle.

    In a larger installation with multiple networks you'd need a Pi on each network. Then each Pi would inform the other Pis who's on which network. So at work you would not only know they are there but which building or floor they are in.

    Think about it and consider updating with the option for WiFi connection.

    0
    None
    CesarD17

    2 years ago

    Hi,

    I like this script, but i don´t get that inquiry.py work on mi RasperyPi2, this is the error message when i type "python inquiry.py":

    performing inquiry...

    Traceback (most recent call last):

    File "inquiry.py", line 12, in <module>

    nearby_devices = bluetooth.discover_devices(duration=8, lookup_names=True, flush_cache=True, lookup_class=False)

    TypeError: discover_devices() got an unexpected keyword argument 'lookup_class'

    Thanks you for your help.

    0
    None
    dyna67

    2 years ago

    How would I adapt the code so that it logs the number of visitors to the house? I want to store the number of guests in like a .txt file