Keyless Entry / Arduino





Introduction: Keyless Entry / Arduino

About: Why would i buy something ready made when i can make it myself with half the features for twice the money? DIY!
                                                                                 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

                            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

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

 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.

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] = {

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   
    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
  lastButtonState = buttonState;
void setup()
  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);
void loop()

  //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;
      offtime = millis() + 10000;  // set the offtime for 30 seconds in the future
      Serial.print(" enter: ");
      switch (eKey)
        case '*':
        case '#':

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

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



    • Woodworking Contest

      Woodworking Contest
    • Clocks Contest

      Clocks Contest
    • Make it Move Contest

      Make it Move Contest

    We have a be nice policy.
    Please be positive and constructive.




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

    Also what Keypad have u you used?

    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 :)


    4 replies

    Wow your fast,also.

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

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


    Huh wonder why, ha.

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

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

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

    1 reply

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