Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Arduino Sketch for DTMF Password Recognition

By: a guest on May 31st, 2012  |  syntax: C++  |  size: 3.02 KB  |  views: 222  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <Password.h>
  2.  
  3. /* Ths sketch will monitor 5 pin
  4.   conected to a MT8870DE DTMF decoder
  5.   chip and send the key pressed to the
  6.   computer by serial comunication.
  7.   In addition, a certain combinaison
  8.   of number will trigger a "unlock"
  9.   or "boot" signal. The pwd in this case will
  10.   be "8413".
  11.  
  12. */
  13.  
  14. int Q1 = 2; /*Q1 bit*/
  15. int Q2 = 3; /*Q2 bit*/
  16. int Q3 = 4; /*Q3 bit*/
  17. int Q4 = 5; /*Q4 bit*/
  18. int StD = 6; /*Delayed Steering; will read high when tone is pressed*/
  19. int keypressed ;
  20. char result ; /*the number presser stored as a character
  21. int pwdlvl = 0 ; /*Number of appended digits*/
  22. Password password = Password( "8413" );
  23.  
  24. void setup() {
  25.  
  26.  Serial.begin(9600); /* Open serial com*/
  27.  /*Pins settings*/
  28.  pinMode(Q1, INPUT);
  29.  pinMode(Q2, INPUT);
  30.  pinMode(Q3, INPUT);
  31.  pinMode(Q4, INPUT);
  32.  pinMode(StD, INPUT);
  33.  
  34. }
  35.  
  36. void loop() {
  37.  
  38.  int toneHeard = digitalRead(StD);
  39.  if (toneHeard == HIGH) {
  40.    delay(250);
  41.    keypressed = interpret() ; /* Go to the interpret function to get the keypressed*/
  42.    Serial.write(keypressed);
  43.    password.append(keypressed);
  44.    pwdlvl++;
  45.    if (pwdlvl == 4){
  46.      Serial.println();
  47.      Serial.print("Guessing password... "); /*debuging purposes*/
  48.      delay(500); /*debuging purposes*/
  49.      if (password.evaluate()){ /*evaluate password*/
  50.          Serial.println("Valid Password");
  51.          Serial.print("Sending 5V signal for 3...");
  52.          delay(1000);
  53.          Serial.print("2...");
  54.          delay(1000);
  55.          Serial.print("1...");
  56.          delay(1000);
  57.          Serial.println("0...");
  58.          password.reset(); /*Reset appended password*/
  59.          pwdlvl = 0; /*Reset the number of appended digits to 0*/
  60.          }
  61.        else {
  62.          Serial.println("Invalid Password");
  63.           password.reset(); /*Reset appended password*/
  64.           pwdlvl = 0; /*Reset the number of appended digits to 0*/
  65.           }
  66.    }
  67.  }
  68.  delay(1);
  69. }
  70.  
  71. int interpret() {
  72.  
  73.   int Q1State = digitalRead(Q1);
  74.   int Q2State = digitalRead(Q2);
  75.   int Q3State = digitalRead(Q3);
  76.   int Q4State = digitalRead(Q4);
  77.  
  78.   if (Q1State == HIGH && Q2State == LOW && Q3State == LOW && Q4State == LOW){result = '1' ;}
  79.   if (Q1State == LOW && Q2State == HIGH && Q3State == LOW && Q4State == LOW){result = '2' ;}
  80.   if (Q1State == HIGH && Q2State == HIGH && Q3State == LOW && Q4State == LOW){result = '3' ;}
  81.   if (Q1State == LOW && Q2State == LOW && Q3State == HIGH && Q4State == LOW){result = '4' ;}
  82.   if (Q1State == HIGH && Q2State == LOW && Q3State == HIGH && Q4State == LOW){result = '5' ;}
  83.   if (Q1State == LOW && Q2State == HIGH && Q3State == HIGH && Q4State == LOW){result = '6' ;}
  84.   if (Q1State == HIGH && Q2State == HIGH && Q3State == HIGH && Q4State == LOW){result = '7' ;}
  85.   if (Q1State == LOW && Q2State == LOW && Q3State == LOW && Q4State == HIGH){result = '8' ;}
  86.   if (Q1State == HIGH && Q2State == LOW && Q3State == LOW && Q4State == HIGH){result = '9' ;}
  87.   if (Q1State == LOW && Q2State == HIGH && Q3State == LOW && Q4State == HIGH){result = '0' ;}
  88.  
  89.   return result;
  90. }