Introduction: Keyless Entry / Arduino

Picture of Keyless Entry / Arduino
                                                                                 Keyless Entry System


 Enter the correct code into the keypad and the servo will unlock the door. Enter the incorrect code and Sorry you stay out. 
There was a couple of stipulations i wanted in my Keyless Entry system:

  1. Helper Light. A light that would come on whenever a key was pressed. Then off after the preset time limit.
  2. An override switch so the servo could be operated without the keypad. 
  3. Some indication that the pass code entered was correct or not.
  4. Powered by a wall charger.
  5. Be able to operate manually during a power outage
With these stipulations i started out to build. 

The Keypad works on a matrix system. Pressing any key will involve 2 wires.
Example if you press number 8 it will effect the wire ROW3 and CLO2. By this the micro controller can determine what key was pressed with only 7 wires from the keypad.
 While this keypad schematic is not correct to this build the theory is still the same. 
This build does not use the external resistors. It takes advantage of the internal pullup resistors in the Atmega328.

Keypad in Arduino Playground.

Step 1: What We Are Going to Need

Picture of What We Are Going to Need
                            Parts and Pieces



  • Atmega328P-UP Bootloaded
  • 28 Pin socket
  • 16Mhz Crystal
  • 22pF caps ( 2 )
  • LM317 voltage regulator
  • LM7805 Voltage regulator
  • 10uF Caps ( 2 )
  • #104 Caps ( 2 )
  • 220R Resistor
  • 1K Resistor
  • 470R Resistor
  • 10K Resistor
  • LED of your choice
  • Tact Switch
  • 5mm Power Connector
  • 2 pin female header
  • 16 Pin Female header
  • Perf Board 70mm x 90mm
  • Flat wire strips 2 wire   4 wire   7 wire  1' long
  • Servo

I would call this a intermittent build as there is several sub build components.

Step 2: The Circuit

Picture of The Circuit

I couldn't find a Keypad in Fritzing so i used 3 mystery parts where it says KEYPAD in the diagram.

Its probably better to use a pullup resistor on the switch instead of a pull down, but either way will work.

Step 3: Code

Picture of Code

 I had some help from  maewert  for the Helper Light.
The Bypass switch the hardest for me. It was a collaboration between sath02 and my self. I am always greatful to these guys for there knowledge.

If you don't have the libraries needed for the sketch they are here for downloading.


               Reference 
 
Arduino on a Breadboard

Keypad Coding

Keypad Tutorial 






#include <Password.h>
#include <Keypad.h>
#include <Servo.h> //tells to use servo library
int pos = 5;    // variable to store the servo position
int button = A0;  // The button will be on Pin 7
Servo myservo; //declares servo
#define DELAY       20  // Delay per loop in ms

Password password = Password( "4444" ); //password to unlock door, can be changed

const byte ROWS = 4; // Four rows
const byte COLS = 3; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3',},
{'4','5','6',},
{'7','8','9',},
{'*','0','#',},
};

byte rowPins[ROWS] = { 5, 4, 3, 2 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 8, 7, 6,};// Connect keypad COL0, COL1 and COL2 to these Arduino pins.


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

unsigned long offtime;
boolean  helper_light_is_on = false; // helper light off
// variables will change:
int buttonState     = 0;  // variable for reading the pushbutton status
int lastButtonState = 0;

void handle_button()
{
     // read the state of the pushbutton value:
     buttonState = digitalRead(button);
    // check if the pushbutton is pressed.
    if (buttonState != lastButtonState) {       
    // Lock release   
    myservo.write(100);
    delay(20);
    digitalWrite(10, HIGH);
    delay(1000); // this delay could be changed to suitable value
    digitalWrite(10, LOW);
    myservo.write(160);// move to lock position after 5 second
    delay(20);
  }
  lastButtonState = buttonState;
}
void setup()
  {
  Serial.begin(9600);
  Serial.write(254);
  Serial.write(0x01);
  delay(200);
  pinMode(10, OUTPUT);  //Helper light
  pinMode(11, OUTPUT);  //green light
  pinMode(12, OUTPUT);  //red light
   pinMode(button, INPUT);
  myservo.attach(9); //servo on digital pin 9 //servo
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
   pinMode(pos, OUTPUT);
   pinMode(button, INPUT);
   delay(200);
}
void loop()
{
  handle_button();
  keypad.getKey();
  myservo.write(5);
  process_helper_light();
  }

  //take care of some special events
  void keypadEvent(KeypadEvent eKey)
{
  switch (keypad.getState())
  {
    case PRESSED:
      // a key is pressed so light the helper light
      helper_light_is_on = true;
      digitalWrite(10,HIGH);
      offtime = millis() + 10000;  // set the offtime for 30 seconds in the future
     
      Serial.print(" enter: ");
      Serial.println(eKey);
      delay(10);
      Serial.write(254);
      switch (eKey)
      {
        case '*':
          checkPassword();
          delay(1);
          break;
        case '#':
          password.reset();
          delay(1);
          break;
        default:
          password.append(eKey);
          delay(1);
      }
    }
  }


void checkPassword()
{
  if (password.evaluate())  //if password is right unlock door
  { 
    Serial.println(" Accepted");
    Serial.write(254);
    delay(10);
    //Add code to run if it works
    myservo.write(90); //160deg
    digitalWrite(11, HIGH);//turn on Green Led
    delay(3000); //wait 5 seconds
    digitalWrite(11, LOW);// turn off Green Led
  }
  else
  {
    Serial.println(" Denied"); //if passwords wrong keep door locked
    Serial.write(254);
    delay(10);
    //add code to run if it did not work
    myservo.write(5);
    digitalWrite(12, HIGH); //turn on RedLed
    delay(3000); //wait 5 seconds
    digitalWrite(12, LOW);//turn off Red Led
   }
{
  if (digitalRead(button) == LOW)
  myservo.write(90);
  //for(pos = 0; pos < 90; pos += 90)  // goes from 0 degrees to 90 degrees
  {                                  // in steps of  degree
   Serial.println(" Opened ");
   myservo.write(pos);
   myservo.write(90); //160deg
   //delay(80);
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
                             
  }
  if (digitalRead(button) == HIGH)
  //else
  //for(pos = 90; pos>=90; pos-=90)  // goes from 90 degrees to 0 degrees
  myservo.write(90);
  {
  Serial.println(" Stay Closed ");
  myservo.write(pos);               // tell servo to go to position in variable 'pos'
  delay(50);           
  myservo.write(5); //160deg
  myservo.write(pos);              // tell servo to go to position in variable 'pos'
    }
  } 
}

// this routine turns off the light when the timer expires
void process_helper_light(void)
{
  if (helper_light_is_on)
  {
    if (millis() >= offtime)
    {
      digitalWrite(10,LOW);  //turn off the helper light
      helper_light_is_on = false;
    }
  }
}

 

Step 4: Build

Picture of Build

This utilizes the Arduino stand alone instead of the complete Arduino board. 
5 volt power regulation from an LM7805
7 volt power regulation from an LM317
LM317 Calculator 



I built this on perf board as can be seen. I used a bigger board than normally i would so i didn't have to cram everything on. Gave me more room to work with. 

Most of the descriptions are on the pictures, so hover over them for the comments.

Installation in the next ible.

Video link

Comments

IshanR (author)2015-11-04

Can I use a normal Arduino UNO rather than a standalone?

Also what Keypad have u you used?

iceng (author)2013-02-11

Nice instructable good pass code device work.
Now I can point to a good project when this comes up as a question every year.

I would add a missed the code counter that penalized the key-er after 5 or 7 bad
entries in a series :)

A

WWC (author)iceng2013-02-11

Wow your fast,also.

Thanks for the comment.
What would the action be for to many incorrect entries? Siren and flashing light?

iceng (author)WWC2013-02-11

I had a circuit penalty device to protect a bicycle that electrified the seat with
a modified Tesla circuit.
It never found commercial interests :(

WWC (author)iceng2013-02-11

Huh wonder why, ha.

Good idea tho, i think a piezo or similar would be appropriate in this case.

iceng (author)WWC2013-02-12

Generally a 5 Minute lock out penalty is sufficient to discourage code breakers.

MicMofMou (author)2013-02-12

Looks quite awesome. Would this also work with codes longer than 4 digits? Say, 9 or 10 digits, for instance?

WWC (author)MicMofMou2013-02-12

Hi thanks for looking and the kind words.
While i have not tried it, i would say so. I don't see why not.

About This Instructable

11,456views

56favorites

License:

Bio: Why would i buy something ready made when i can make it myself with half the features for twice the money? DIY!
More by WWC:3D Pinted Spool ReelHard Drive Tachometer for a Desktop Computer4093 Schmidt Trigger / Fan Speed Regulation
Add instructable to: