Introduction: Smart Front Door

The following instructable will show how I created my smart front door system. The system works as follows:

  1. There's a 4-row password
  2. 3 Buttons are 1,2,3
  3. The last button is to reset the password

Reset Instructions

  1. Press the reset button 3 times. (Blue light flashes on)
  2. Input a new password, length 4 numbers.
  3. Press the reset button again. (Blue light flashes 3 times to confirm).

NOTE: When inputting a value lower or higher than 4 you may get a red light flashing indicating an error.

Step 1: Arduino Setup

The first step is to get all the buttons, LED's and Servo's setup in the correct order.

REQUIREMENTS

  • 1 LED Red
  • 1 LED Blue
  • 1 Arduino Uno
  • Power cable
  • Wires
  • 1 Servomotor
  • 4 Push buttons
  • 6 Resistors. (4x 10k, 2x 220 ohm).

Make sure that the wires are going into the correct pins for the next step.

Step 2: Coding

Now the main systems are ready and setup it's time to plug your Arduino into a computer.

Download the main software and open it up.

Input the following code down below, compile it, and upload it to your Arduino.

// Made by Niels Poelder
#include 
// All servo's
Servo lockServo;
int servoState;
// All pins
const int buttonPins[] = {2, 3, 4};
int buttonStates[] = {0, 0, 0};
int lastButtonStates[] = {0, 0, 0};
int arrayLength;
const int resetButtonPin = 7;
const int redLedPin =  11;
const int greenLedPin = 12;      
// Password
String inputPassword = "";
String Password = "1232";
bool isLocked = true;
// Misc values
int resetButtonCounter = 0;
int resetButtonState = 0;
int lastresetButtonState = 0;
bool passChangeInEffect = false;
void setup() {
  Serial.begin(9600);
  arrayLength = sizeof(buttonPins) / sizeof(buttonPins[0]) - 1;
  
  for(int btc = 0; btc <= arrayLength; btc++){
    pinMode(buttonPins[btc], INPUT);
    //Debugging
    Serial.print("Button ");
    Serial.print(btc);
    Serial.print(" Assigned to PIN ");
    Serial.println(buttonPins[btc]);
  }
  pinMode(redLedPin, OUTPUT);
  pinMode(greenLedPin, OUTPUT);
  
  pinMode(resetButtonPin, INPUT);
  lockServo.attach(9); 
  int servoPos = map(180, 0, 180, 90, 160);
  lockServo.write(servoPos);
}
void loop() {  
  resetButtonState = digitalRead(resetButtonPin);
  Serial.println(inputPassword + " INPUT");
  // PASSWORD CHECKER STARfT
  if(inputPassword == Password && !passChangeInEffect){
    if(isLocked){
      int servoPos = map(0, 0, 180, 90, 160);
      lockServo.write(servoPos);
      isLocked = false;
      Serial.println("The lock has been opened");
    }
    else{
      Serial.println("The lock has been closed");
      int servoPos = map(180, 0, 180, 90, 170);
      lockServo.write(servoPos);
      isLocked = true;
    }
    showLight(greenLedPin, 4);
       
  }else if(inputPassword != Password && inputPassword.length() >= 4 && !passChangeInEffect){
    showLight(redLedPin, 4);
    
  }
  // PASSWORD CHECKER END
  
  // INPUT BUTTONS START
  for(int btc = 0; btc <= arrayLength; btc++){
    buttonStates[btc] = digitalRead(buttonPins[btc]);
    
    if (buttonStates[btc] != lastButtonStates[btc]){
      if(buttonStates[btc] == HIGH){
        inputPassword = inputPassword + (btc + 1);
        if(!passChangeInEffect){
        resetButtonCounter = 0;
        }
      }
    }
  lastButtonStates[btc] = buttonStates[btc];
  }
  // INPUT BUTTONS END
  // RESET BUTTON START
  if(resetButtonCounter == 3 && !passChangeInEffect){
    passChangeInEffect = true;
    showLight(greenLedPin, 1);
  }
  
  if (resetButtonState != lastresetButtonState){
    if (resetButtonState == HIGH) {
      if(resetButtonCounter < 3 && !passChangeInEffect){
        resetButtonCounter += 1;
        inputPassword = inputPassword = "";
      }
      if(passChangeInEffect && inputPassword.length() == 4){
        Password = inputPassword;
        inputPassword = "";
        resetButtonCounter = 0;
        passChangeInEffect = false;
        flashLight(greenLedPin, 3);
      }
      else if(passChangeInEffect && inputPassword.length() < 4){
        passChangeInEffect = false;
        resetButtonCounter = 0;
        flashLight(redLedPin, 3);
      }
    } 
  }
  
  lastresetButtonState = resetButtonState;
  // RESET BUTTON END
}
void showLight(int lightPin, int seconds){
      int interval = seconds * 1000;
      digitalWrite(lightPin, HIGH);
      delay(interval);
      inputPassword = "";
      digitalWrite(lightPin, LOW);
}  
void flashLight(int lightPin, int count){
      int interval = 200;
      inputPassword = "";
      for(int num = 1; num <= count; num++){
        delay(interval);
        digitalWrite(lightPin, HIGH);
        delay(interval);
        digitalWrite(lightPin, LOW);
      }
}

Step 3: Making the Outer Casing.

For the casing, you'll need the following things.

  1. A small wooden door.
  2. A small string.
  3. Drilling machine
  4. Glue and wood glue
  5. Wood
  6. Stone (Optional)

Preparing the door

Step 1:

Drill a hole in the door, about 1 mm.

Step 2:

Put the tiny string through the hole and tie a knot on the outside.

Step 3:

Put the rope through the Servo head. Tie a knot and make sure that the door is able to swing open and close with the rope.

Step 4:

If this is all working put a little bit of glue on the rope on the outside of the door to make sure that it'll never go loose.

Preparing the case

  1. Get the correct measurements of the wooden box and make sure that there's room for error.
  2. Make sure that you have a hole in the front door to fit the door in.
  3. Make sure that you make an access port on the top.
  4. Saw the pieces of the house.
  5. Glue everything together but the top.
  6. Put the front door in and glue the servo against the door (Make sure that the door is fully able to open and close).

Step 4: Putting Everything Together.

Now it's time to put everything together. Make sure that there's a correct amount of height for your wires and buttons to make it through the top of the casing. NOTE: You may want to apply glue to the breadboard/print plate to make sure it's fully stuck.

  1. Drill a small hole in the side for the Arduino cable.
  2. Put in the Arduino.
  3. Put in the breadboard/print plate.
  4. Wire everything up.
  5. Check if everything is working
  6. Glue it all together when possible
  7. You're Finished!