Project tutorial
Grovey sLocks - Access Control Through A Smart Door Lock

Grovey sLocks - Access Control Through A Smart Door Lock © MIT

Looking to open home to airBnB? Grovey sLocks is an Internet connected BLE enabled device allowing users entry, once approved via the cloud.

  • 1,139 views
  • 1 comment
  • 7 respects

Components and supplies

Ardgen 101
Arduino 101 & Genuino 101
×1
Seeed Grove Starter kit for Arduino&Genuino 101
×1
Seeed Grove - Relay
×2
Adafruit Lock-style Solenoid - 12VDC
Alternative is Electric Door Release / Strike (Fail Safe). E.g. search on eBay or purchase from RS Components
×1
SparkFun LED Tactile Button - Blue
This is optional / nice to have, as can use touch sensor and LED from Grove Starter Kit
×1
SparkFun LED Tactile Button Breakout
This is optional / nice to have, as can use touch sensor and LED from Grove Starter Kit
×1
Electricimp
Electric Imp
×1
Electric 20imp 20april
Electric Imp April Breakout Board
×1
Rhxvhx2dhljmbtloxexc
Arduino Proto Shield
Used to mount the Electric Imp Breakout and to mount a 5.08 Screw Terminal for the Electric Strike / Solenoid.
×1
Adafruit 12 VDC 1000mA regulated switching power adapter
×1
Adafruit White Enclosure for Arduino
×1
G4 LED capsule lamp
Add current limiting resistor of choice (used 220 Ohm in project)
×1

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

GitHub Pages - Websites hosted directly from GitHub repository
Website for project includes html, css, AngularJS and javascript
Cloudflare
This handles the https and domain name settings (unique domain name optional)
Ide web
Arduino IDE
Electric Imp Cloud IDE (Squirrel)
Google Physical Web
Android App: https://play.google.com/store/apps/details?id=physical_web.org.physicalweb&hl=en IOS: Download Chrome Browser App
AngularJS

About this project

Introduction

Grovey Slocks hatched from a smart home (airBnB) idea put forward for the Arduino 101 - Invent Your Future! competition: https://www.hackster.io/contests/Intel-Arduino-101/ideas/4828

As described, Grovey Slocks is targeted at those people who are looking to open their homes/residential properties to the holiday homes / rental market, such as airBnB for example, and want a keyless access control system for their smart home.

Grovey Slocks is essentially an Internet connected BLE enabled device which allows a guest entry once their details have been checked / approved with the data stored in the cloud / back end system. For the purposes of this project the booking details of the guest are already stored in the back-end system (usually that would come from an online booking system).

Grovey Slocks is purposely designed to operate via a web app rather than a dedicated mobile app. This allows users access to the application from a website URL, which is obtained via a BLE beacon configured using Eddystone. The BLE beacon provides the guest with a convenient hassle-free way of pulling up the correct web page onto their smartphone web-browser. Other options could also be included within the web app such as scanning and potentially connecting with BLE module directly using the web Bluetooth API. This has been demonstrated in other Hackster projects (e.g. BLElectric Light 101).

The multi-step access process, as demonstrated in the videos (button press on door as well as phone) is probably a little convoluted, but this was by design for the proof of concept (POC) to provide future functionality enhancements and to provide additional layers of security (e.g. need to provision an unknown smartphone at first presentation to the door control system and also challenge the user to confirm their credentials). It is also seen as a starting point to help reimagine the standard access control process.

For this competition I was also testing Arduino 101's capabilities (e.g. timers) and have to say that I think 101 is pretty awesome, as peripherals such as the embedded BLE module do not get in the way by hogging IO pins etc. The components provided within the Grove kit were also put to full use. For example, RGB backlight within LCD was used to great effect, by changing backlight color to represent different things (hopefully this can be seen in the video demos).

System Overview

Grovey Slocks is built using an Arduino / Genuino 101 microcontroller and the accompanied Grove Starter kit from SeeedStudio. In addition 2 x grove relays were used to control an Electric Strike Lock, which is used to unlock / lock a door, and a LED light which is triggered at night (low light levels). Both the 12V Electric Strike Lock and the 12V LED light were purchased from RS Components. Then as a product substitution, a Sparkfun LED tactile button was used instead of the Grove Touch Sensor and separate LED, simply to allow a button / LED to neatly fit within an Adafruit LCD enclosure.

For WiFi connectivity and a web service back end, Electric Imp was used. Electric Imp was ideal for this project as it saved me loads time not having to develop all the back-end stuff from scratch, which I would have had to do if using AWS for example (would've used mqtt messaging and/or http RESTful service, APIgateway, Lambda and dynamoDB). The AngularJS based web app / html web site developed for the application was hosted (free) on github and for the sakes of having a nice clean URL for the BLE beacon, a custom domain name was purchased (circa $5) for this purpose. Finally Cloudfare was used to ensure that the web domain is https compliant (a requirement for Eddystone formatted BLE beacons transmitting URLs).

The system is powered using a 12V +1A DC power supply.

Putting it together (Hardware)

Thanks to the Seeedstudio Grove kit, there is no customised hardware required. It is almost plug and play.

To start, connect the Grove RGB LCD to an I2C connector as shown. Note that the Seeedstudio RGB LCD requires a 5V input voltage, so set switch on the Grove Base Shield to 5V. This is similarly required for the Grove relays which also require 5V.

Thankfully the Arduino 101 is 5V tolerant so no level shifting is required. There are 2 digital sensors which are the push buttons and there are 2 Analog sensors (Rotary Angle sensor and Light sensor). The higher voltage does make a difference is with Analog sensors such as the Grove Rotary Angle sensor and the Grove Light sensor, but once properly calibrated this does not make a difference to the outcome.

A number of outputs are used in the project, namely LED status indicators for the outside push button (for the user) and for the BLE device (for device owner - in case not working properly), and then there is a PWM buzzer for user alerts.

An Arduino proto shield was used to mount the Electric Imp Wifi module and a 2-pin screw terminal, which is used to handle the 12V power to the electric strike lock and the G4 LED light bulb. Some additional wiring was also added to the proto shield to handle serial communication between Electric Imp pin's 5 & 7 and Arduino 101 via either pin's 3 & 4 using the Softwareserial library or the pin's 0 & 1 using the default serial port. Arduino Pin 9 was also connected to Pin 1 of the Electric Imp to provide an "Arduino Ready" signal and Imp Wakeup signal but this was not implemented in POC. A further option, which was also not implemented in POC, would be to connect Arduino Reset to Pin 2 of the Electric Imp to allow the Imp to reset the Arduino if necessary.

Pulling it together (Software)

Pulling the software together and integrating the different elements of the project to make it bug free and resilient is very much still a work in progress. It was a case of do what is necessary for the POC to prevent the tail of the project (i.e. web app code) from wagging the dog (i.e. Arduino 101 code).

The application has 3 coding modules:

Arduino: The Arduino code handles serial communication with the Electric Imp using softwareserial library (really for POC only to allow for debug information via default Serial port), the BLE Eddystone configuration (using this library https://github.com/bneedhamia/CurieEddystoneURL button presses / reading digital input values, angle sensor analog input data which is compared again min and max values stored in EEPROM using Arduino EEPROM library, light level analog readings, LED flashing for user guidance using the CurieTimerOne library and the backlight color and LCD messaging using the I2C wire library and the Seeedstudio rgb_lcd library.

Electric Imp: The Electric Imp device code is the gateway handling two-way serial communication with Arduino 101 as well as two-way communication with the Electric Imp agent, which manages the http web service with the dedicated web app. As this project is focused on using Arduino 101 to control door access and monitor door movement, I am not going into the detail of how you connect Electric Imp to your local WiFi network etc. For that detail, please refer to the Electric Imp startup guide.

Web App: The website code is using the Model-View-Controller (MVC) software architecture to manage the user interface and logic, dynamic web page updates and the data transfer, with ajax requests using cross-origin resource sharing (CORS), between webpage and the Electric Imp cloud gateway. The core application framework used for the web app is Angularjs. The web page design uses bootstrap html/css/javascript responsive framework by way of adapting a free template found on the web from startbootstrap. For the purposes of this project description I am assuming you know a bit about AngularJS and developing websites using html5. For AngularJS please refer to their developer guide (note I found their tutorials a little complicated and found more suitable tutorials on youtube).

All the code is provided in github (see code section for link).

Here are some of the key aspects within the Arduino code, starting with the BLE component.

This part of the code is a based off the example given in bneedhamia github repository (see above link). Note that it is no longer needed to modify the CurieBLE.h file as per comment in his example, as this library has since been updated. The part that does need modifying is the following declaration:

const char* MY_URL = "http://www.intel.com"; 

You need to change this URL link. Note that only http is no longer accepted by Google. There is also a restriction on the string length - namely max 17 characters. If your URL is longer you would need to use a URL shortener, such as Google's URL shortener for example. Otherwise the code is pretty much the same. Note that if the BLE code does not initialise properly with the URL, the code will stop.

if (!initEddystoneUrlFrame(TX_POWER_DBM, MY_URL)) { 
   return; // don't start advertising if the URL won't work. 
 } 

Further if the other BLE routines do not initialise correctly the code will stop.

 ble.setAdvertisedServiceUuid(eddyService.uuid()); 
 ble.setAdvertisedServiceData(eddyService.uuid(), urlFrame, urlFrameLength); 
 ble.begin(); 
 setupSucceeded = true; 
 // If BLE setup() failed, do nothing 
 if (!setupSucceeded) { 
   delay(1); 
   return; 
 } 

Now briefly reviewing the setup() process. Here the code looks to see if the Rotary Angle sensor has been calibrated by looking for min. and max. values stored within EEPROM.

 calAngleMin = EEPROMReadInt(MIN_EEPADDR); 
 calAngleMax = EEPROMReadInt(MAX_EEPADDR); 

If there's null values or if the min and max values are too similar (within 3) then it automatically jumps to the calibration routine.

if (!calAngleMax || abs(calAngleMin - calAngleMax) < 3) { 
   Serial.println(F("Entering Calibration Mode")); 
   calibrateDoorAngleSensor(); 
 } 
 else canMONITORdoor = true; 

Note the rotation of your door as you would need to change the code. In my case the potentiometer was at a higher value when the door was closed and at a lower value when the door was open.

Within setup (as in during power up) it also performs a basic check to see if the indoor button is held down. If it detects this, it will then allow the user manually calibrate the rotary angle sensor again.

 byte btncntr = 0; 
 for (byte i = 0; i < 20; i++) { 
   if (digitalRead(PIN_BTN2)) btncntr++; 
   delay(100); 
 } 
 if (btncntr > 10) calibrateDoorAngleSensor(); 
 // ======= end of door calibration stuff 

Then within the main loop() routine the code essentially is doing:

1. Checking if serial communication available from Imp

2. Periodic check (every TIMERCYCLETRIGGER) where is measures light levels and sends a "ping" to the imp module to tell all ok.

3. Check for indoor button press (this takes precedence over outdoor button press) then check for outdoor button press. If outdoor button is pressed this activates the curietimer (CurieTimerOne library) to manage periodic LED flashes.

4. If door strike relay activated monitor how long before turning off relay.

5. Check to see if door angle needs monitoring (via canMONITORdoor && MONITORdoor flags). If door monitoring trigger then takes analog measurements of angle rotation sensor every 500ms. The readings are then mapped against 0 to 100 to determine the degree in which door is open. Then the result is categorised to determine whether door is "ajar", "open", "wide-open" or "closed".

6. If the buzzer is activated monitor how long before turning off.

7. If night light is activated monitor how long before turning off relay.

There are also a number of LCD routines to handle different messages and background colours.

Code

Schematics

Schematic
Schematic of Genuino 101 microcontroller with attached sensors, actuators and Imp wifi module

Comments

Author

Photo
gerrikoio
  • 2 projects
  • 2 followers

Additional contributors

Published on

March 26, 2017

Members who respect this project

DefaultPhoto

and 5 others

See similar projects
you might like

Similar projects you might like

SMART CUBE: A New Way to Control Your Home

Project tutorial by Alberto Sartori

  • 13,531 views
  • 7 comments
  • 30 respects

Control Door Lock Remotely Using Smartphone

Project tutorial by soardr

  • 4,223 views
  • 0 comments
  • 12 respects

Rampiot - Cool Smart Lock

Project tutorial by Robinson Mesino

  • 4,255 views
  • 2 comments
  • 29 respects

RFID Door Access Control with Counter

Project tutorial by sarful

  • 2,049 views
  • 0 comments
  • 6 respects

Smart Garbage Monitoring System Using Arduino 101

Project tutorial by Technovation

  • 21,413 views
  • 7 comments
  • 32 respects

The Arduino Gatekeeper

Project tutorial by Timothy Le

  • 15,569 views
  • 0 comments
  • 50 respects
Add projectSign up / Login