Post

Electronic Dorm Lock Project

During my freshman year at UMass Amherst, I made a password controlled lock for my dorm door because I didn't feel like bringing my keys everywhere.

Electronic Dorm Lock Project

I’d often come back from a long day of class just to realize that I had forgotten my keys in my room. So instead of learning how to be responsible with my belongings, I decided to make this contraption instead.

Demo

The finished project turned out a lot better than I thought. I’d say it took me about 3 days to fully create everything. Here’s how it went:

The idea came after I started messing around with an Arduino that I had stolen borrowed from the makerspace. At first, I wasn’t exactly sure what I was doing, so I began by hooking up a microservo to an infrared sensor. To control it, I programmed the Arduino to read signals from my fan’s IR remote. I found it fascinating that I could repurpose an everyday device for a completely different function. That simple experiment got me hooked, and I decided my next step would be to build something bigger and better; Maybe something that would make my life more convenient by not having to carry my keys everywhere.

I knew from the beginning that I wanted it to be password controlled, but I didn’t know at first how to actually make my door lock turn. I figured the easiest way would be to attach a servo on the back of the door to turn the deadbolt. I took a few measurements of the lock and eventually 3D printed a small mount.

(image of mount)

My initial print was too large, so I made a quick change and reprinted it. Luckily it was the right size to fit on the lock. After some tests to ensure that the servo could in fact turn the lock, I 3D printed the servo mount and took some plastic blocks to secure the servo in place.

Next was the Arduino part. I spent most of the time looking at Arduino documentation just to write the code. The display was the trickiest part because I was using SPI communication, which meant more wires for me to worry about. I also had a lot of trouble with the actual password system of the lock, particularly with storing the password in the EEPROM. After a few hours of debugging however, I managed to get it working.

For the finishing touches, I cut a piece of black acrylic and carefully arranged the layout of the lock. The project was complete, and it worked surprisingly well. Unfortunately, the batteries would die after about 6 hours, so it wasn’t exactly practical. But at least it garnered a few funny reactions from my roommates.

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <Keypad.h>
#include <LiquidCrystal.h>
#include<EEPROM.h>
#include <Servo.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 5, 4, 3}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

//lcd display
const int rs = 12, en = 11, d4 = A5, d5 = A4, d6 = A3, d7 = A2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
char password[4];
char initial_password[4];
Servo motor;
const int buzzer = A0;


void setup() {
  pinMode(buzzer, OUTPUT);
  motor.attach(2);
  lcd.begin(16, 2);
  Serial.begin(9600);
  int password [4] = { 1, 2, 3, 4 };  
  int keys [4];
  EEPROM.write(0, '1');
  EEPROM.write(1, '3');
  EEPROM.write(2, '7');
  EEPROM.write(3, '9');
  for(int j=0;j<4;j++){
    initial_password[j]=EEPROM.read(j);
  }
  motor.write(0);
  delay(5000);
  motor.write(90);
}

int i=0;
int k=0;
void loop() {
  char customKey = customKeypad.getKey();
  if (customKey){
    i+=1;
    tone(buzzer,329);      
    delay(100);
    noTone(buzzer);   
  }
  if (i==0){
    lcd.clear();
    lcd.write("Hovan's Dorm");
    lcd.setCursor(0, 1);
    lcd.write("Press any key:");
    i+=1;
  }
  if (i==2) {
      delay(200);
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.write("Enter Password:");   
      lcd.setCursor(0,1);   
    }
  if (i > 2 && i < 7) {
    if (customKey){
      lcd.write(customKey);
      password[k++]=(customKey);
      }   
    }
  if (k==4){
    delay(200);
    for(int j=0;j<4;j++){
      initial_password[j]=EEPROM.read(j);
    }
    if(!(strncmp(password, initial_password,4))){
      lcd.clear();
      lcd.write("Pass Accepted");
      tone(buzzer,329);      
      delay(150);
      noTone(buzzer);     
      tone(buzzer,392);            
      delay(200);
      noTone(buzzer);    
      lcd.setCursor(0,1);
      delay(1500);
      lcd.write("Unlocking door...");
      delay(1000);
      motor.write(0);
      delay(8000);
      motor.write(90);
    }
    else{
      lcd.clear();
      lcd.write("Wrong Password");
      tone(buzzer,250);            
      delay(500);
      noTone(buzzer);   
      delay(4000);
    }
    i=0;
    k=0;
    }
}
This post is licensed under CC BY 4.0 by the author.

Trending Tags