Pages: [1]   Go Down
Author Topic: An Easy Password Base Lock System for Arduino using IR Remote  (Read 5032 times)
0 Members and 1 Guest are viewing this topic.
Odisha, India
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I searched a little to find any straight and easy to use Code for building a Password based Door Opening and Closing System, but could not find one. So I made a little modification to The IRRemote Library's Default Example and included the Password Library, and with very little effort this Code was Built.I will update after adding the Servo Controlled Sliding Door Code, but for now Here it is if someone else is also searching for the same.


#include <IRremote.h>
#include <Password.h>

Password password = Password( "1234" );

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  irrecv.enableIRIn(); // Start the receiver
  Serial.begin(9600);
  Serial.print("Ready");
}

// Compare two tick values, returning 0 if newval is shorter,
// 1 if newval is equal, and 2 if newval is longer
// Use a tolerance of 20%
int compare(unsigned int oldval, unsigned int newval) {
  if (newval < oldval * .smiley-cool {
    return 0;
  } 
  else if (oldval < newval * .smiley-cool {
    return 2;
  } 
  else {
    return 1;
  }
}

// Use FNV hash algorithm: http://isthe.com/chongo/tech/comp/fnv/#FNV-param
#define FNV_PRIME_32 16777619
#define FNV_BASIS_32 2166136261

/* Converts the raw code values into a 32-bit hash code.
 * Hopefully this code is unique for each button.
 */
unsigned long decodeHash(decode_results *results) {
  unsigned long hash = FNV_BASIS_32;
  for (int i = 1; i+2 < results->rawlen; i++) {
    int value =  compare(results->rawbuf, results->rawbuf[i+2]);
    // Add value into the hash
    hash = (hash * FNV_PRIME_32) ^ value;
  }
  return hash;
}

void loop() {
  if (irrecv.decode(&results)) {
    unsigned long hash = decodeHash(&results);
    switch (hash) {
    case 0xB7CEF1C7: // 1 (10)
      password.append('1');
      break;
    case 0x3F3C26A7: // 2
      password.append('2');
      break;
    case 0x3021612B: // 3
      password.append('3');
      break;
    case 0x7EFFC747: // 4
      password.append('4');
      break;
    case 0xD8AD1F4B: // 5
      password.append('5');
      break;
    case 0x2CAD10E3: // 6
      password.append('6');
      break;
    case 0x1D924B67: // 7
      password.append('7');
      break;
    case 0xB93DEFA7: // 8
      password.append('8');
      break;
    case 0x12EB47AB: // 9
      password.append('9');
      break;
    case 0x275A9FCB: // 0
      password.append('0');
      break;
    case 0x20934FE3: //Power Button
      checkPassword(); 
      break;
    case 0x253F247: //TV/AV 
      password.reset();
      break;
    default:
      Serial.print("Unknown ");
      Serial.println(hash, HEX);   
    }
    irrecv.resume(); // Resume decoding (necessary!)
  }
}

void checkPassword(){
  if (password.evaluate()){
    Serial.println("Success");
    Serial.println("Code For Opening Door");
    //Add code to run if it works
    
    password.reset();
  }else{
    Serial.println("Wrong");
    Serial.println("Please Try Again");
    //add code to run if it did not work
    
    
  }
}



Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you upload IRremote.h and password.h please ?
Logged

Odisha, India
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here are the Lwo Libraries, However you could have just googled too.

* Password.zip (5.56 KB - downloaded 34 times.)
* IRremote.zip (32.3 KB - downloaded 27 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

// Use FNV hash algorithm: http://isthe.com/chongo/tech/comp/fnv/#FNV-param
#define FNV_PRIME_32 16777619
#define FNV_BASIS_32 2166136261

/* Converts the raw code values into a 32-bit hash code.
 * Hopefully this code is unique for each button.
 */
unsigned long decodeHash(decode_results *results) {
  unsigned long hash = FNV_BASIS_32;
  for (int i = 1; i+2 < results->rawlen; i++) {
      //this line  miss   a  variable. do not work.   it should be  //-->   int value =  compare(results->rawbuf, results->rawbuf[i+2]);   
    // Add value into the hash
    hash = (hash * FNV_PRIME_32) ^ value;
  }
  return hash;
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

  int value =  compare(results->rawbuf, results->rawbuf[i+2]);
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

  int value =  compare(results->rawbuf   [  i  ] , results->rawbuf[i+2]);      [    i  ]  after rawbuf ----- can not be posted ?   smiley-kitty smiley-evil smiley-evil
Logged

Pages: [1]   Go Up
Jump to: