Knock, Knock – This Remote Door Opener Using Arduino Uno is No Joke!

Knock, Knock – This Remote Door Opener Using Arduino Uno is No Joke!

 

Who’s knocking on your door? How would you like to know you’re protected from any unwanted visitors with a password protected remote control door opener you can operate using Arduino Uno and the internet?

Here at Vilros, we appreciate the need for privacy, so we’re excited about this project inspired by phpoc_man that gives you control over your door with a pattern password. 

You’re probably already familiar with a pattern password, as this is what most people use to prevent unwanted access to their smartphones.  Now you can use this same feature with Arduino, which makes it possible for important real-world protection, like keeping your private affairs behind closed doors. 

In this project, you’ll create a pattern password for Arduino. When a user gives the correct password, they will be able to rotate the image of a door handle seen via the internet.  This will trigger a web send command that will prompt Arduino relay control to deactivate an electromagnetic lock for your door.

Check out this list of all the equipment you’ll want to get before you start:

  • Arduino UNO + Genuino UNO
  • Wi-Fi Shield 2 (designed to work for Arduino)
  • 4-Port Relay Board
  • Electromagnetic Lock 

1. The Set-Up You Will Create

Once this project is all set-up, you will be able to unlock any door remotely using a pattern password on the internet.

You’ll want to check out this video to make sure you get all the set-up details.

2. Connect All Your Wires

Next, you’ll want to make sure each piece of your equipment set-up is connected properly: 

First the Wi-Fi shield need to be connected with Arduino. Then the relay shield connects with the Wi-Fi shield. Lastly, you’ll want to connect the relay shield to the lock (you can find a layout of all the connections here.)

Note: for the relay shield, you’ll want to be sure to set the relay work to the NC mode (Normal Closed).

3. Next Steps

Once you have all the wiring set up, it’s time to get your code and upload it to Arduino.  Then, you’ll want to use this instruction to upload the door.php to the Wi-Fi shield.

You’ll also need to replace the IP address for the Wi-Fi shield. Instead, you’ll want to use this page to access your door.

Lastly, you’ll want to create the pattern that will serve as your password. Then, just rotate the door handle so that you can open the door.

Vilros

4. The Code You’ll Need

Here’s a copy of the code you’ll need for Arduino:

arduino web server - pattern unlock */ 

#include <Phpoc.h>

#include <PhpocExpansion.h>

#define CMD_AUTH                  0

#define CMD_CTRL 1

#define ACCESS_ACCEPTED                      "0\r\n"

#define ACCESS_UNAUTHORIZED           "1\r\n"

#define DOOR_STATE_OPEN                    "2\r\n"

#define DOOR_STATE_CLOSE "3\r\n"

#define DOOR_TIMEOUT_MS                  10000

 

PhpocServer server(80);

ExpansionRelayOutput relay(1, 0);

String pattern;

bool authenticated;

 

unsigned long lastActiveTime;

 

void setup() {

Serial.begin(9600);

while(!Serial)

Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);

//Phpoc.begin();

server.beginWebSocket("web_pattern");

Serial.print("WebSocket server address: ");

Serial.println(Phpoc.localIP());

// initialize expansion board

Expansion.begin();

pattern = String("1,4,8,6,3");

authenticated = false;

lastActiveTime = 0;

}

void loop() {

// wait for a new client:

PhpocClient client = server.available();

if (client) {

 String data = client.readLine();

if(data) {

int pos = data.indexOf(':');

int cmd = data.substring(0, pos).toInt();

Serial.print("<<");

Serial.print(data);

if(cmd == CMD_AUTH) {

String reqPattern = data.substring(pos+1);                                                      reqPattern.remove(reqPattern.indexOf(13));

reqPattern.remove(reqPattern.indexOf(10));

if(pattern.equals(reqPattern)) {

authenticated = true;

sendResponse(ACCESS_ACCEPTED, 3);

lastActiveTime = millis();

}

else {

authenticated = false;                                                                                          sendResponse(ACCESS_UNAUTHORIZED, 3);

}

 }

else

if(cmd == CMD_CTRL) {

if(authenticated) {

int control = data.substring(pos+1).toInt();

if(!control){

relay.off();                                                                            sendResponse(DOOR_STATE_CLOSE, 3);

} else {

relay.on();                                                                                  sendResponse(DOOR_STATE_OPEN, 3);

}

lastActiveTime = millis();

}

else {

sendResponse(ACCESS_UNAUTHORIZED, 3);

}

}

}

}

if (authenticated && ((millis() - lastActiveTime) > DOOR_TIMEOUT_MS)){

authenticated = false;

sendResponse(ACCESS_UNAUTHORIZED, 3);

relay.off();

delay(500);

sendResponse(DOOR_STATE_CLOSE, 3);

}

}

void sendResponse(char *data, int len) {

server.write(data, len);

Serial.print(">>");

Serial.print(data);

}

 

Step on through!  Now that everything is connected and up and running, you should now be able to grant access to any visitors from anywhere you can access the internet.  Who will be the first people who will gain access to enter through your door?

If you’ve enjoyed this project, be sure to check back here on our Vilros Projects blog for more ideas you can try using Arduino and Raspberry Pi.


Leave a comment

Comments will be approved before showing up.


Also in Getting Started

How to format SD card and download NOOBS
How Do I Erase SD Card and Download NOOBS?

If you would like to try formatting & reflashing your Micro SD card on your own please read this post! 
Read More
7 Must-Have Raspberry Pi Accessories | Vilros.com
7 Must-Have Raspberry Pi Accessories

Read More
3 Great Raspberry Pi Kits for Beginners | Vilros.com
3 Great Raspberry Pi Kits for Beginners

Here are 3 of the best starter kits and some of their key features:
Read More

GET IN TOUCH

MAKE:INSPIRE TEAM