Find all your DIY electronics in the MakerShed. 3D Printing, Kits, Arduino, Raspberry Pi, Books & more!

arduioo-week

This project allows you to open a solenoid lock from a PhoneGap app using the Bluetooth Serial Plugin and the new Adafruit Bluetooth LE break-out board for the Nordic Semiconductor nRF8001 chip.

BluetoothLock

 

Steps

Step #1: Wire the project together

PrevNext
Controlling a Lock with an Arduino and Bluetooth LEControlling a Lock with an Arduino and Bluetooth LEControlling a Lock with an Arduino and Bluetooth LE
  • Wire the project together as shown in the diagram (and photograph) above.
  • The solenoid draws a lot of current, can't run off USB power or 9V battery so we use the external power supply. The Darlington transistor allows us to switch the 12V power to the lock using an Arduino pin.
  • The Adafruit Bluefruit LE hardware is Bluetooth Low Energy, but we're using it to do serial communication similar to Bluetooth Classic's Serial Port Profile (SPP). There is no SPP for BLE, that's not really how BLE works, so people create custom "serial like" services using the GATT. Adafruit is re-using the UUIDs from the Nordic Semiconductor's UART service.

Step #2: Get the code

PrevNext
Controlling a Lock with an Arduino and Bluetooth LE

Step #3: Upload the Arduino sketch

PrevNext
Controlling a Lock with an Arduino and Bluetooth LE

Use the Arduino IDE to upload the BluetoothLock sketch from the arduino directory to your board.

Step #4: Test the lock

PrevNext
Controlling a Lock with an Arduino and Bluetooth LE
  • Install Adafruit Bluefruit LE Connect on your iPhone or iPad.
  • Launch Bluefruit LE and choose "UART monitor"
  • Once connected, you can send data to the Arduino and receive responses.
  • Send u12345. The green light should light up and the lock will open.
  • Send an invalid code, u2222, the red light will light up.
  • Note that the lock will ignore incoming data without the "u" (unlock) prefix.
  • If you have an Android device that supports BLE, test the lock using nRF UART.

Step #5: Install PhoneGap

PrevNext
Controlling a Lock with an Arduino and Bluetooth LE
  • Go ahead and install PhoneGap (aka Cordova) on your Mac. It isn't going to work with Xcode 5.1, unless you apply patches, so you should probably stuck with Xcode 5.0 if you can.
  • Download and install NodeJS, or install it using a package management system like Homebrew or MacPorts.
  • Then install Cordova using NPM, which comes with NodeJS.
    $ npm install -g cordova
    See the Cordova Documentation for more information.

Step #6: Building the PhoneGap project

PrevNext
Controlling a Lock with an Arduino and Bluetooth LE
  • The project contains only the PhoneGap (aka Cordova) code. Both the iOS platform and BluetoothSerial plugin need to be installed into the project before running.
    $ cd BlutoothLock/cordova
    $ cordova platform add ios
    $ cordova plugin add https://github.com/don/BluetoothSerial
    $ cordova prepare
    $ open platforms/ios/Lock.xcodeproj
  • Open the Xcode project, and choose the target device in Xcode.
  • Build and deploy though Xcode.
  • You can modify the application by editing the files in $PROJECT_HOME/cordova/www. Make sure you run cordova prepare before redeploying the app through Xcode.

Step #7: Running the application

PrevNext
Controlling a Lock with an Arduino and Bluetooth LEControlling a Lock with an Arduino and Bluetooth LEControlling a Lock with an Arduino and Bluetooth LE

Open the application on your iPhone and connect to the lock.


Alasdair Allan

Alasdair Allan is a scientist, author, hacker, tinkerer and co-founder of a startup working on fixing the Internet of Things. He spends much of his time probing current trends in an attempt to determine which technologies are going to define our future.


blog comments powered by Disqus

Featured Products from the MakerShed

Follow

Get every new post delivered to your Inbox.

Join 25,554 other followers