ddsitzmann
Published

Keypad Garage Opener

Replaced a bad keypad on the outside of my garage door.

IntermediateWork in progress6,467
Keypad Garage Opener

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Garage Door Fob
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 220 ohm
Resistor 220 ohm
×4
5 mm LED: Green
5 mm LED: Green
×1
5 mm LED: Red
5 mm LED: Red
×1
LED, Blue Green
LED, Blue Green
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Servo_fob_arduino_mount

This positions the servo to press the button on the fob. Wayne Dalton fob. Custom needed for other brands

Keypad case

Allows the keypad to be mounted to wall and adds the LEDs. Uses Adafruit Keypad 3845.

Schematics

Schematic

Code

Garage Door Keypad

Arduino
See instructions in code
//  Garage Door Opener using servo to press remote button
//
//  Correct entry of 4 digit code will illuminate the Green LED
//  Incorrect entry of 4 digit code will illuminate the Red LED
//
//  To change the code:
//  Press the "#" button on keypad and the Blue LED will illimunate
//  While Blue LED is illuminated, enter the initial password
//    Correct entry will illuminate the Blue and Yellow LEDs
//    Incorrect entry will illuminate the Red LED (must start over and press "#" on keypad)
//  While the Blue and Yellow LEDs are illuminated, enter the new password.
//    Successful change of password will illuminate the Green LED.
//
//  To reset the password to 1234, press the reset button

#include<Keypad.h>
#include<EEPROM.h>
#include<Servo.h>

  Servo ServoMotor;

  char password[4];
  char initial_password[4],new_password[4];
  int i=0;
  int LED_G = 14;
  int LED_R = 15;
  int LED_B = 16;
  int LED_Y = 17;
  char key_pressed=0;

  const int Reset = 12;
  int value1 = HIGH;

  const byte rows = 4; 
  const byte columns = 3; 
  char keys[rows][columns] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
  };

  byte row_pins[rows] = { 7, 2, 3, 5};
  byte column_pins[columns] = { 6, 8, 4};   
  Keypad keypad_key = Keypad( makeKeymap(keys), row_pins, column_pins, rows, columns);

  //#define LED_R 10 // define red LED
  //#define LED_G 11 // define green LED

void setup()
  {
  Serial.begin (9600);
  pinMode(Reset, INPUT);
  pinMode(LED_R, OUTPUT);
  pinMode(LED_G, OUTPUT);
  pinMode(LED_B, OUTPUT);
  pinMode(LED_Y, OUTPUT);
  delay(1000);
  ServoMotor.attach(13);

  // check if the password has been changed
  if (EEPROM.read(256) != 123) { // not equal to 123
    EEPROM.write(256, 123); // write value of 123 to byte 256
    initialpassword(); // set first password to 1234
  }
    else { // if byte 256 is equal to 123
      EEPROM.get (0, password); // get last password before power failure
    }
  }

void loop()
{
  digitalWrite(LED_R, LOW);
  digitalWrite(LED_G, LOW);
  key_pressed = keypad_key.getKey();

  value1 = digitalRead (Reset);
  if (value1 == HIGH)
    initialpassword();
  
  if(key_pressed=='#')
    change();

  if (key_pressed)
  {

    password[i++]=key_pressed;
    Serial.println(key_pressed);
      }

  if(i==4)
  {
    delay(200);
    for(int j=0;j<4;j++)
      initial_password[j]=EEPROM.read(j);
    if(!(strncmp(password, initial_password,4)))
    {

      Serial.println("Password Accepted");
      digitalWrite(LED_G, HIGH);
      ServoMotor.write(78);
      delay(delay);
      ServoMotor.write(90);
      Serial.println("Press # to change");
      delay(delay);
      Serial.println("Enter Password:");
      i=0;

    }

    else
    {
      digitalWrite(LED_R, HIGH);
      Serial.println("Wrong Password");;
      Serial.println("Press # to change");
      delay(delay);
      Serial.println("Enter Password");

      i=0;
    }
  }
}

void change()

{
  int j=0;
  Serial.println("Current Password");
  digitalWrite(LED_B, HIGH);
  while(j<4)
  {
    char key=keypad_key.getKey();
    if(key)
    {
      new_password[j++]=key;
      Serial.println(key);
    }
    key=0;
  }
  delay(delay);
  if((strncmp(new_password, initial_password, 4)))
  {
    Serial.println("Wrong Password");
    Serial.println("Try Again");
    delay(200);
    digitalWrite(LED_B, LOW);
    digitalWrite(LED_R, HIGH);
    delay(delay);
    digitalWrite(LED_R, LOW);
  }
  else
  {
    j=0;
    Serial.println("New Password:");
    digitalWrite(LED_Y, HIGH);
    while(j<4)
    {
      char key=keypad_key.getKey();
      if(key)
      {
        initial_password[j]=key;
        Serial.println(key);
        EEPROM.write(j,key);
        j++;
      }
    }
    Serial.println("Password Changed");
    delay(200);
    digitalWrite(LED_B, LOW);
    digitalWrite(LED_Y, LOW);
    digitalWrite(LED_G, HIGH);
    delay(delay);
    digitalWrite(LED_G, LOW);
  }
  Serial.println("Enter Password");
  key_pressed=0;
}

void initialpassword(){
  for(int j=0;j<4;j++)
    EEPROM.write(j, j+49);
  for(int j=0;j<4;j++)
    initial_password[j]=EEPROM.read(j);
} 

Credits

ddsitzmann

ddsitzmann

1 project • 3 followers

Comments