Due to a gracious donation of TI CC3200-LaunchXL's to Michigan State University from Texas Instruments, I was able to create a smart lock that can send real-time updates to any phone anywhere in the world with only a few pieces of hardware and a little bit of time. Using a reed switch, which is attached to a door and a small magnet placed on the end of a deadbolt thumb-latch, when the reed switch circuit is completed or broken, the TI CC3200-LaunchXL reads that value as an input, transforms it into a message and sends the message to a phone application through IFTTT.
This idea was originally thought of due to many renters being unable to install the security devices that they want because most security products are invasive and include some type of physical and potentially damaging installation process, which many renters are not able to do. So, creating a smart lock that you can tape to your door allows for renters to be able to have a security device without having to worry about damages or fines that are filed from landlords.
Design ProcessThere are three main components to creating your smart lock. First there is the installation, which requires you to attach the reed switch, magnet, and TI CC3200-LaunchXL to the door, which will be detailed below. Then you must create an IFTTT applet and download the IFTTT phone application. Lastly, you need to write and upload the sensor code to the TI CC3200-LaunchXL.
Hardware InstallationAs seen above, you will need your TI CC3200-LaunchXL, a reed switch, a small magnet, electrical tape, female/female jump wires, and most likely an extension cord.
To start, tape a small magnet to the end of your deadbolt thumb-latch.
Before connecting the reed switch to the TI CC3200-LaunchXL, connect one jump wire to an end of the reed switch and then connect another jump wire to the other end of the reed switch. Now, connect one jump wire to pin 9 (marked as "P01") and connect the other jump wire to GND in J20 in the bottom right corner of the TI CC3200-LaunchXL.
Now, turn the deadbolt thumb-latch until it is in the locked position. Once the thumb-latch is in the locked position, tape the reed switch, which is attached to the TI CC3200-LaunchXL, so that the magnet on the end of the thumb-latch is touching the reed switch. Now, finishing securing the TI CC3200-LaunchXL and power cord safely to the door and power outlet.
Your door should now look like this:
Now that your hardware is set up, we can now create an IFTTT applet and write the code.
Setting Up Your IFTTT Webhooks Applet1. First, go to www.ifttt.com
2. Next, create an account, or sign in to an existing one if you already have one
3. Click on your user's icon in the top right and select "Create"
4. Click "This" from "If This Then That"
5. Search and select "Webhooks, " and then select "Receive a web request"
6. Enter a custom event name of your choosing, we will be using "status_change, " then "Create Trigger"
7. Click "That" from "If This Then That"
8. Search and select "Notifications, " and then select "Send a notification from the IFTTT app"
9. In "Message, " type "Device "{{Value1}}" detected that your door is now {{Value2}}on{{OccurredAt}}" then click "Create action"
11. Feel free to enter your own applet name or leave it as is and click "Finish"
Now your applet is connected and ready to send messages from the sensor to your phone.
Modifying the code written by Hackster user @adrianF for a TI LaunchPad project, we were able to modify the code to take inputs from a reed switch and send the data to our IFTTT applet which communicates with the phone application.
You must make a few modifications in the code in order to compile and make the code work correctly.
1. Change the SSID & Password to the credentials of your desired WiFi network
2. Change the IFTTT_KEY to your key
3. Change the IFTTT_EVENT to the event name you chose when creating your IFTTT applet. We chose "status_change" for this tutorial.
4. [OPTIONAL] Feel free to change the device ID, as this will be the ID that is shown on your application screen. If you are installing the smart lock for your front door, using a device ID such as "FrontDoor" may be wise.
Below is the code that should be loaded into Engeria and uploaded to the TI CC3200-LaunchXL:
/*
Repeating Wifi Web Client
This sketch connects to a a web server and makes a request
Circuit:
* WiFi shield attached to pins SPI pins and pin 7
created 23 April 2012
modified 31 May 2012
by Tom Igoe
modified 13 Jan 2014
by Federico Vanzati
modified 6 July 2014
by Noah Luskey
modified 12 Oct 2015
by Adrian Fernandez (IFTTT trigger)
modified 14 April 2020
by Cody Carter & Tony Miller (reed switch integration)
This code is in the public domain.
Circuit:
* CC3200 WiFi LaunchPad or CC3100 WiFi BoosterPack
with TM4C or MSP430 LaunchPad
*/
#ifndef __CC3200R1M1RGC__
// Do not include SPI for CC3200 LaunchPad
#include <SPI.h>
#endif
#include <WiFi.h>
// Define pin reed switch is connected to
const int REED_SWITCH = 9;
// your network name also called SSID
char ssid[] = "ssid here";
// your network password
char password[] = "ssid password here";
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(50,62,217,1); // numeric IP for Google (no DNS)
char server[] = "maker.ifttt.com"; // name address for Google (using DNS)
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;
int trigger = 0;
int last = 0;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
// attempt to connect to Wifi network:
Serial.print("Attempting to connect to Network named: ");
// print the network name (SSID);
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED) {
// print dots while we wait to connect
Serial.print(".");
delay(300);
}
Serial.println("\nYou're connected to the network");
Serial.println("Waiting for an ip address");
while (WiFi.localIP() == INADDR_NONE) {
// print dots while we wait for an ip addresss
Serial.print(".");
delay(300);
}
Serial.println("\nIP Address obtained");
// We are connected and have an IP address.
// Print the WiFi status.
printWifiStatus();
/* Enable internal pullup.
* Without the pin will float and the example will not work */
pinMode(REED_SWITCH, INPUT_PULLUP);
attachInterrupt(REED_SWITCH, sendRequest, CHANGE); // Interrupt is fired whenever button is pressed or unpressed
Serial.println("CHANGE STATUS OF DOOR LOCK");
}
void loop() {
String IFTTT_KEY = "IFTTT-key-here";
String IFTTT_EVENT = "status_change"; // IFTTT Maker Event Name here
if(trigger != last){
ifttt_trigger(IFTTT_KEY, IFTTT_EVENT);
Serial.println("STATUS OF DOOR LOCK CHANGED");
}
last = trigger;
}
//******************************************************************************************
// This method makes a HTTP connection to the server & does a GET request for user name
// Simply pass in the badge ID to query as a String.
// Returns string:
// - Returns "<NAME>"if badge ID is registered
// - Returns "NULL" if badge ID is not registered
// - Returns "FAIL" if REST API failed
//******************************************************************************************
String ifttt_trigger(String KEY, String EVENT) {
String name = "";
// close any connection before send a new request.
// This will free the socket on the WiFi shield
client.stop();
// if there's a successful connection:
if (client.connect(server, 80)) {
String status;
if (trigger == 0){
status = "LOCKED";
}
else{
status = "UNLOCKED";
}
// This is optional. You can send additional data to IFTTT along with your HTTP POST that triggers the action
String PostData = "{\"value1\" : \"FrontDoor\", \"value2\" : \"" + status + "\"}";
Serial.println("connected to server... Getting name...");
// send the HTTP PUT request:
String request = "POST /trigger/";
request += EVENT;
request += "/with/key/";
request += KEY;
request += " HTTP/1.1";
Serial.println(request);
client.println(request);
client.println("Host: maker.ifttt.com");
client.println("User-Agent: Energia/1.1");
client.println("Connection: close");
client.println("Content-Type: application/json");
client.print("Content-Length: ");
client.println(PostData.length());
client.println();
client.println(PostData);
client.println();
}
else {
// if you couldn't make a connection:
Serial.println("Connection failed");
return "FAIL"; // rest API failed...
}
// Capture response from the server. (10 second timeout)
long timeOut = 4000;
long lastTime = millis();
while((millis()-lastTime) < timeOut){ // Wait for incoming response from server
while (client.available()) { // Characters incoming from the server
char c = client.read(); // Read characters
Serial.write(c);
}
}
Serial.println();
Serial.println("Request Complete!");
//return name; // Return the complete name received from server
return "SUCCESS";
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
void sendRequest(){
if(digitalRead(REED_SWITCH)){
trigger = 1;
}
else{
trigger = 0;
delay(1000);
}
}
All you have to do now is download the IFTTT application on your phone, sign in, turn on notifications and you are ready to receive notifications from your smart lock!
Comments
Please log in or sign up to comment.