YouTube player

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.



Project Steps

Wire the project together

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.

Get the code

The source code for this project is available on Github. You can clone the repository or download a zip file.

$ git clone

or download a zip file

Upload the Arduino sketch

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

Test the lock

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.

Install PhoneGap

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.

Building the PhoneGap project

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

$ 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.

Running the application

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