ARDUINO Projects

  • Password

    What if you want to make a security home door or keycode for your box or anything has business with keypad password then you arrive.
    This project base on Arduino IDE for make it simple.

    Demonstration

    We connecting the column of Keypad C4, C3, C2, C1 to Arduino digital pins
    and D2, D3, D4, D5 and the Row of the keypad R1, R2, R3, R4 to digital pins D6, D7, D8, D9.

    Post
    Digital pin D12 blinking if the password was wrong, the digital pin D13 will be activated for 2 seconds if the password right.
    I use two liberals in this project the first one is for reading data from keypad and to cancel the wrong number after 25 seconds.
    So the code will be not staying in the memory of the processor and that useful and no know one your password.
    Install Timer one library :- TimerOne.h
    Arduino code
    #include <TimerOne.h>
    #include <Keypad.h>
    volatile byte code;
    volatile byte erro;
    volatile byte counter_sec;
    int good=13;
    int bad=12;
    char pass[]="10562893";
    const byte row=4;
    const byte cols=4;
    char key [row][cols]={
      {'1','2','3','A'},
      {'4','5','6','B'},
      {'7','8','9','C'},
      {'#','0','*','D'},
    };
    byte rowpins[row]={6,7,8,9};
    byte colspins[cols]={5,4,3,2};
    Keypad keys=Keypad(makeKeymap(key),rowpins,colspins,row,cols);
    void setup()
    {
      Serial.begin(9600);
      pinMode(good,OUTPUT);
      pinMode(bad,OUTPUT);
      Timer1.initialize(5000000);
      Timer1.attachInterrupt(code_cancel);
      Timer1.stop();
    }
    void loop()
    {
      char mykeys=keys.getKey();
      if(mykeys > 0) 
      {Timer1.resume();counter_sec=0;}
      if(mykeys=='*' || mykeys=='#')
      {
        code=0;erro=0;
        digitalWrite(bad,LOW);
        
      }
      if(mykeys == pass[code])
      {
        Serial.println(mykeys);
        Serial.println(pass[code]);
        code++;
      }
      else
      {
        if(mykeys > 0 && mykeys!=pass[code])
      {
        Serial.println("erro");Serial.println(mykeys);erro++;code=0;}
      }
      if (code==8)lock(true);
      
      if (erro==4)
      { lock(false);erro=0;code=0;}
    
    }
    
    void lock( boolean lockt)
    {
      if (lockt==true)
      {
        digitalWrite(good,HIGH);
        digitalWrite(bad,LOW);
        delay(2000);
        digitalWrite(good,LOW);
        code=0;erro=0;
      }
      if (lockt==false)
      {
        digitalWrite(bad,HIGH);
        delay(250);
        digitalWrite(bad,LOW);
        delay(250);
        digitalWrite(bad,HIGH);
        delay(250);
        digitalWrite(bad,LOW);
        code=0;erro=0;
        
      }
    }
    
    void code_cancel()
    {
      counter_sec++;
      if (counter_sec>=5)
      {
     Serial.println("timer off");
     code=0;erro=0;Timer1.stop();
     counter_sec=0;
      }
    }