Akash RavichandranPrabhakaran Senthilnathan
Published © MIT

AirLock

No more fumbling for keys! The Airlock is your new, intelligent, secure way to lock and unlock everything.

AdvancedFull instructions providedOver 2 days4,723
AirLock

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
IR receiver (generic)
×8
IR transmitter (generic)
×8
ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
LED (generic)
LED (generic)
×1
Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
RDDRONE-FMUK66
NXP RDDRONE-FMUK66
×1
KIT-HGDRONEK66
NXP KIT-HGDRONEK66
×1

Software apps and online services

Arduino IDE
Arduino IDE
ARTIK Cloud for IoT
Samsung ARTIK Cloud for IoT

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)
Laser cutter (generic)
Laser cutter (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Airlock Design

After the welding stage, the complete Airlock.

Schematics

Airlock Ir Array

Airlock gets the values from these IR array setup.

Code

Code for Airlock

Arduino
Fully functional Airlock
/************************AIRLOCK 2016***********************/
/************Copyrights AIRLOCK development team************/
/********If any change, edit in Notepad++ or Sublime********/

#include<SoftwareSerial.h>
#define PASS_SIZE		10
#define NO_OF_USERS		20
#define DELAY 			100
#define DELAY_L 		400
#define DELAY_LL		2000
#define DELAY_LLL   8000
#define DEBUG			true

SoftwareSerial esp8266(9,8);

String NETWORK_NAME	=	"fadsgE";
String NETWORK_PASS	=	"XAKDAK";
String ROUTER_PORT	=	"333";
String IP 			=	"192.168.0.101";
String PORT 		=	"3000";


int avail_s1 =    425;
int avail_s2 =    669;
int avail_s3 =    610;
int avail_v1 =    305;

int n_avail_s1 =  423;
int n_avail_s2 =  660;
int n_avail_s3 =  600;
int n_avail_v1 =  305;

int lo_s1_1 =   420;          //Grid 1
int up_s1_1 =   505;

int lo_s2_1 =   645;
int up_s2_1 =   700;

int lo_s3_1 =   570;
int up_s3_1 =   612;

int lo_v1_1 =   450;

int lo_s1_2 =   430;          //Grid 2
int up_s1_2 =   505;

int lo_s2_2 =   620;
int up_s2_2 =   690;

int lo_s3_2 =   580;
int up_s3_2 =   632;

int lo_v1_2 =   330;
int up_v1_2 =   450;

int lo_s1_3 =   410;          //Grid 3
int up_s1_3 =   445;

int lo_s2_3 =   630;
int up_s2_3 =   700;

int lo_s3_3 =   585;
int up_s3_3 =   645;

int lo_v1_3 =   290;
int up_v1_3 =   327;

int lo_s1_4 =   460;          //Grid 4
int up_s1_4 =   605;

int lo_s2_4 =   605;
int up_s2_4 =   670;

int lo_s3_4 =   545;
int up_s3_4 =   575;

int lo_v1_4 =   245;
int up_v1_4 =   275;

int lo_s1_5 =   428;          //Grid 5
int up_s1_5 =   525;

int lo_s2_5 =   660;
int up_s2_5 =   790;

int lo_s3_5 =   570;
int up_s3_5 =   700;

int lo_v1_5 =   245;
int up_v1_5 =   295;

int lo_s1_6 =   410;          //Grid 6
int up_s1_6 =   425;

int lo_s2_6 =   645;
int up_s2_6 =   730;

int lo_s3_6 =   630;
int up_s3_6 =   800;

int lo_v1_6 =   250;
int up_v1_6 =   315;

int lo_s1_7 =   710;          //Grid 7

int lo_s2_7 =   610;
int up_s2_7 =   780;

int lo_s3_7 =   555;
int up_s3_7 =   600;

int up_v1_7 =   284;

int lo_s1_8 =   405;          //Grid 8
int up_s1_8 =   680;

int lo_s2_8 =   870;

int lo_s3_8 =   565;
int up_s3_8 =   860;

int lo_v1_8 =   240;
int up_v1_8 =   276;

int lo_s1_9 =   403;          //Grid 9
int up_s1_9 =   425;

int lo_s2_9 =   630;
int up_s2_9 =   800;

int lo_s3_9 =   930;

int lo_v1_9 =   245;
int up_v1_9 =   288;

void setup()
{
  //Choose the Serial baud rate
  Serial.begin(115200);
  esp8266.begin(115200);

	pinMode(A0,INPUT);
	pinMode(A1,INPUT);
	pinMode(A2,INPUT);
	pinMode(A3,INPUT);
	pinMode(3,OUTPUT);
	pinMode(4,OUTPUT);
	pinMode(5,OUTPUT);
	pinMode(6,OUTPUT);
  
	//Resetting ESP8266
  sendData("AT+RST\r\n",5000,DEBUG); // reset module
  sendData("AT+CWMODE=3\r\n",1000,DEBUG); // configure as access point

  //Connecting with WiFi
	String cwjap = "AT+CWJAP=\""+NETWORK_NAME+"\",\""+NETWORK_PASS+"\"\r\n";
	String wifi_port = "AT+CIPSERVER=1,"+ROUTER_PORT+"\r\n"; 

	sendData(cwjap, 8000, DEBUG);
	sendData("AT+CIFSR\r\n",4000,DEBUG); // get ip address
  sendData("AT+CIPMUX=1\r\n",2000,DEBUG); // configure for multiple connections
  sendData(wifi_port,3000,DEBUG);// turn on server on port 333

  //Connecting with server
	/*
  String server_connect = "AT+CIPSTART=\"TCP\",\"" + IP + "\"," + PORT + "\r\n";
	sendData(server_connect,5000,DEBUG);
	*/
  
}

int s1, s2, s3, v1;              			    //IR input variables
int UserPassword[NO_OF_USERS][PASS_SIZE];	//Checking Password array
int PassLen[NO_OF_USERS];					        //Password Length

void ReadFromIR()
{
	s1=analogRead(A0);
	s2=analogRead(A1);
	s3=analogRead(A2);
	v1=analogRead(A3);
}

void DigiWrite(bool val)
{
	digitalWrite(4,val);
	digitalWrite(3,val);
	digitalWrite(5,val);
}

int DoorOpen()
{
  digitalWrite(6,HIGH);
	digitalWrite(3,HIGH);
	digitalWrite(5,LOW);
	return 1;
}

void DoorClose()
{
  digitalWrite(6,LOW);
	digitalWrite(3,HIGH);
  delay(DELAY_LL);
  digitalWrite(3,LOW);
	digitalWrite(5,LOW);
}

void Warning()
{
  digitalWrite(5,HIGH);
  delay(DELAY_LL);
  digitalWrite(5,LOW);
}

bool IR_ready()
{
	ReadFromIR();
	return (s1 > avail_s1 || s2 > avail_s2 || s3 > avail_s3 || v1 > avail_v1);
}

bool Not_Ready()
{
	return (s1 < n_avail_s1 && s2 < n_avail_s2 && s3 < n_avail_s3 && v1 < n_avail_v1);
}

bool Grid(int n)
{
	if(n == 1)
		return (s1 > lo_s1_1 && s1 < up_s1_1 && s2 > lo_s2_1 && s2 < up_s2_1 && s3 > lo_s3_1 && s3 < up_s3_1 && v1 > lo_v1_1);
	if(n == 2)
		return (s1 > lo_s1_2 && s1 < up_s1_2 && s2 > lo_s2_2 && s2 < up_s2_2 && s3 > lo_s3_2 && s3 < up_s3_2 && v1 > lo_v1_2 && v1 < up_v1_2);
	if(n == 3)
		return (s1 > lo_s1_3 && s1 < up_s1_3 && s2 > lo_s2_3 && s2 < up_s2_3 && s3 > lo_s3_3 && s3 < up_s3_3 && v1 > lo_v1_3 && v1 < up_v1_3);
	if(n == 4)
		return (s1 > lo_s1_4 && s1 < up_s1_4 && s2 > lo_s2_4 && s2 < up_s2_4 && s3 > lo_s3_4 && s3 < up_s3_4 && v1 > lo_v1_4 && v1 < up_v1_4);
	if(n == 5)
		return (s1 > lo_s1_5 && s1 < up_s1_5 && s2 > lo_s2_5 && s2 < up_s2_5 && s3 > lo_s3_5 && s3 < up_s3_5 && v1 > lo_v1_5 && v1 < up_v1_5);
	if(n == 6)
		return (s1 > lo_s1_6 && s1 < up_s1_6 && s2 > lo_s2_6 && s2 < up_s2_6 && s3 > lo_s3_6 && s3 < up_s3_6 && v1 > lo_v1_6 && v1 < up_v1_6);
	if(n == 7)
		return (s1 > lo_s1_7 && s2 > lo_s2_7 && s2 < up_s2_7 && s3 > lo_s3_7 && s3 < up_s3_7 && v1 < up_v1_7);
	if(n == 8)
		return (s1 > lo_s1_8 && s1 < up_s1_8 && s2 > lo_s2_8 && s3 > lo_s3_8 && s3 < up_s3_8 && v1 > lo_v1_8 && v1 < up_v1_8);
	if(n == 9)
		return (s1 > lo_s1_9 && s1 < up_s1_9 && s2 > lo_s2_9 && s2 < up_s2_9 && s3 > lo_s3_9 && v1 > lo_v1_9 && v1 < up_v1_9);
}


int GetPassword(int pass[])
{
	bool grid[10] = {0};
	int len = 0;
	delay(DELAY_L);
	DigiWrite(1);
	while(1){
		ReadFromIR();
		for(int i=1; i<10; i++)
		{
			if(!grid[i] && Grid(i))
			{
				delay(DELAY);
				ReadFromIR();
				if(!grid[i] && Grid(i))
				{
					pass[len++] = i;
					grid[i] = 1;
					Serial.println(i);
				}
			}
		}
		if(Not_Ready())
		{
			DigiWrite(0);
			for(int i=1; i<10; i++)
			{
				grid[i] = 0;
			}
			break;
		}
	}
	return len-1;
}

bool PassMatches(int In[], int n, int user)
{
	for(int i=0; i<=n; i++)
	{
		if(In[i] != UserPassword[user][i])
		{
			return 0;
		}
	}
	return 1;
}

int User=0;
int user;
int FreshPassword = 0;
int DoorStatus = 0;
String Door;

int testval = 0;
int testvalid = 0;
int passright = 0;

void loop()
{
	int InPassword[PASS_SIZE] = {0};
	int InPasslen;
  
	if(esp8266.available())
	{
		//Let us assume this as to set password
		if(esp8266.find("+IPD,"))
		{
      Serial.println("Inside IPD");
			delay(300); 
			int connectionIdIPD = esp8266.read()-48;
			//Which user   is sending!
			if(esp8266.find("u="))
			{
        Serial.println("Keep the hand");
        goto Bypass;
        /*
        if(IR_ready())
        {
          User++;
          Serial.println("Entering Setting Password!");
  				PassLen[User] = GetPassword(UserPassword[User]);
          Serial.println("Password saved successfully!");
				  FreshPassword = 1;
        }
				goto CheckPass;*/
			}
			else if(esp8266.find("o="))
			{
        Serial.println("O=");
				int open = DoorOpen();
				String UserLog1 = "GET /list/make?log[userid]=Admin&log[status]=Eopen";
				String UserLog2 = "&commit=Create HTTP/1.1\r\nHost: " + IP + ":" + PORT + "\r\n\r\n";
				String cipsendlen = String(UserLog1.length()+UserLog2.length()-6);
				sendData("AT+CIPSEND="+cipsendlen+"\r\n",2000,DEBUG);
				sendData(UserLog1+UserLog2, 5000, DEBUG);
			}
     /*
			String closeCommand = "AT+CIPCLOSE=";
			closeCommand+=connectionId+"\r\n";
			sendData(closeCommand,1000,DEBUG);
			*/
		}
	} 
  
 //Testing Code
    while(Serial.available()>0){
      testval = Serial.read() - 48;
      Serial.println("Entered one");
      if(testval == 1){
Bypass: 
        User++;
        testval = 0;
        testvalid = 1;
        Serial.println("User");
        Serial.println(User);
      }
    }
    if(testvalid == 1 && IR_ready())  //if hand is inside
    {
      Serial.println("Entering Setting Password!");
      PassLen[User] = GetPassword(UserPassword[User]);
      Serial.println("Password saved successfully!");
      testvalid = 0;
    }
 //End
CheckPass: 
	if(testvalid == 0 && IR_ready())	//if hand is inside
	{
    Serial.println("Entering Getting Password!!");
		InPasslen = GetPassword(InPassword);
    Serial.println("Got test password");
		if (FreshPassword == 1)
		{
			user = User;
			goto DirectCheck;
		}
		for(user=0; user<NO_OF_USERS; user++)
		{
DirectCheck:
      passright = 0;
			if(InPasslen == PassLen[user])
			{
				if(PassMatches(InPassword, InPasslen, user))
				{
          passright = 1;
          if(DoorStatus == 0)
          {
            DoorStatus = 1;
            Door = "Open";
  					int open = DoorOpen();
            Serial.println("************************");
            Serial.println("User");
            Serial.println(user);
            Serial.println("Door Opened");
            Serial.println("************************");
          }
          else
          {
            DoorClose();
            Door = "Close";
            DoorStatus = 0;
            Serial.println("************************");
            Serial.println("User");
            Serial.println(user);
            Serial.println("Door Closed");
            Serial.println("************************"); 
          }

         
          
          /*sendData("AT+CIPSTART=\"TCP\",\"192.168.0.101\",3000\r\n",5000,DEBUG);
          sendData("AT+CIPSEND=99\r\n",2000,DEBUG);
          int connectionId = esp8266.read()-48;
          String sam = "GET /list/insert?log[userid]=1&list[status]=1&commit=Create HTTP/1.1\r\nHost: 192.168.0.101:3000\r\n\r\n";
          sendData(sam,5000,DEBUG);
          String closeCommand = "AT+CIPCLOSE=";
          closeCommand+=connectionId;
          closeCommand+="\r\n";
          sendData(closeCommand,3000,DEBUG);*/
          
          //String server_connect = "AT+CIPSTART=\"TCP\",\"" + IP + "\"," + PORT + "\r\n";
          //sendData(server_connect,5000,DEBUG);
          //Serial.println(Door);
					//String UserLog = "GET /list/insert?log[userid]="+ String(user) +"&log[status]="+Door+"&commit=Create HTTP/1.1\r\nHost: "+IP+":"+PORT+"\r\n\r\n";
          //String UserLog = "GET /list/insert?log[userid]=1&log[status]=1&commit=Create HTTP/1.1\r\nHost: 192.168.0.101:3000\r\n\r\n";
          //String cipsendlen = String(UserLog.length()-6);
          //Serial.println(UserLog);
          //Serial.println(UserLog.length());
          //Serial.println(cipsendlen);
					//sendData("AT+CIPSEND="+cipsendlen+"\r\n",2000,DEBUG);
					//sendData(UserLog, 5000, DEBUG);
          //String closeCommand = "AT+CIPCLOSE=";
          //closeCommand+=connectionId;
          //closeCommand+="\r\n";
          //sendData(closeCommand,3000,DEBUG);
          
				}
			}
      if (passright == 1)
      {
         FreshPassword = 0;
         break;
      }
		}
    if(passright != 1)  //WRONG PASSWORD
    {
          Warning();
          Serial.println("************************");
          Serial.println("WRONG PASSWORD!");
          Serial.println("************************");
    }
	}
}

//DO NOT CHANGE ANYTHING BELOW THIS

String sendData(String command, const int timeout, boolean debug)
{
	String response = "";
	esp8266.print(command); // send the read character to the esp8266
	long int time = millis();
	while( (time+timeout) > millis())
	{
		while(esp8266.available())
		{ 
			char c = esp8266.read(); // read the next character.
			response+=c;
		}  
	}
	if(debug)
	{
		Serial.print(response);
	}
	return response;
}

Calibrating Airlock sensor values

Arduino
Helps to Calibrate the sensor values.
void setup() 
{
 Serial.begin(9600);
 pinMode(A0,INPUT);
 pinMode(A1,INPUT);
 pinMode(A2,INPUT);
 pinMode(A3,INPUT);
 pinMode(A4,INPUT);
 pinMode(A5,INPUT);
 pinMode(3,OUTPUT);
 pinMode(4,OUTPUT);
 pinMode(5,OUTPUT);
}
int s1,s2,s3,v1;
void loop() 
{
 digitalWrite(3,HIGH);
  digitalWrite(4,HIGH);
  digitalWrite(5,HIGH);
  s1=analogRead(A0);
  s2=analogRead(A1);
  s3=analogRead(A2);
  v1=analogRead(A3);
  Serial.println(s1);
  Serial.println(s2);
  Serial.println(s3);
  Serial.println(v1);
  Serial.println();
  Serial.println();
  Serial.println();
  delay(1000);
}

Artik Cloud using Curl for Airlock

JSON
curl -H "Content-Type: application/json" -H "Authorization: Bearer 687dc03a09374c33b7cbcde5cc7b6594" "https://api.artik.cloud/v1.1/users/self"

Credits

Akash Ravichandran

Akash Ravichandran

15 projects • 100 followers
Developer and a Learner
Prabhakaran Senthilnathan

Prabhakaran Senthilnathan

1 project • 1 follower

Comments