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.
The source code for this project is available on Github. You can clone the repository or download a zip file.
$ git clone http://github.com/don/BluetoothLock.git
or download a zip file https://github.com/don/BluetoothLock/archive/master.zip
Use the Arduino IDE to upload the BluetoothLock sketch from the arduino directory to your board.
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.
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.
Then install Cordova using NPM, which comes with NodeJS.
$ npm install -g cordova
See the Cordova Documentation for more information.
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
Make sure you run
cordova prepare before redeploying the app through Xcode.
Open the application on your iPhone and connect to the lock.