Advertisement
Kharulnisya

locking system

Oct 14th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. #include "FPS_GT511C3.h"
  2. #include "SoftwareSerial.h"
  3. #include <Servo.h>
  4. #define SERVO_PIN 9 // sets servo to pin 9
  5. int count = 0; // current display count
  6. int pos = 0; // variable to store the servo position
  7. int nonactiveLED = 13;
  8. int readingLED = 12;
  9. int idLED = 11;
  10. int deniedLED = 10;
  11.  
  12. // Hardware setup - FPS connected to:
  13. // digital pin 4(arduino rx, fps tx)
  14. // digital pin 5(arduino tx - 560ohm resistor - fps tx - 1000ohm resistor - ground)
  15. // this voltage divider brings the 5v tx line down to about 3.2v so we dont fry our fps
  16.  
  17. FPS_GT511C3 fps(51, 52);
  18.  
  19.  
  20. Servo myservo; // create servo object to control the lock
  21.  
  22.  
  23. void setup()
  24. {
  25. Serial.begin(9600);
  26. delay(100);
  27. fps.UseSerialDebug = true;
  28. fps.Open();
  29. fps.SetLED(true);
  30. // myservo.attach(SERVO_PIN); // attaches the servo to pin 9
  31. pinMode(nonactiveLED, OUTPUT);
  32. pinMode(readingLED, OUTPUT);
  33. pinMode(idLED, OUTPUT);
  34. pinMode(deniedLED, OUTPUT);
  35. //zero();
  36. }
  37.  
  38. void loop()
  39. {
  40. digitalWrite(nonactiveLED, HIGH);
  41. // Identify fingerprint test
  42. if (fps.IsPressFinger())
  43. {
  44. count++;
  45.  
  46. }
  47.  
  48.  
  49. {
  50. delay(50);
  51. switch (count) {
  52. case 0:
  53. openDoor();
  54. Serial.print("Door Is Open");
  55. break;
  56. case 1:
  57. closeDoor();
  58. Serial.print("Door Is Closed");
  59. break;
  60. case 2:
  61. openDoor();
  62. Serial.print("Door Is Open");
  63. break;
  64. case 3:
  65. closeDoor();
  66. Serial.print("Door Is Closed");
  67. break;
  68. case 4:
  69. openDoor();
  70. Serial.print("Door Is Open");
  71. count = 0;
  72. break;
  73.  
  74.  
  75.  
  76.  
  77. }
  78. }
  79. //delay(100);
  80. }
  81.  
  82.  
  83. void openDoor()
  84. {
  85. fps.CaptureFinger(false);
  86. int id = fps.Identify1_N();
  87. if (id <200)
  88. {
  89. myservo.attach(SERVO_PIN); // attaches the servo to pin 9
  90. digitalWrite(nonactiveLED, LOW);
  91. delay(50);
  92. digitalWrite(readingLED, HIGH);
  93. delay(50);
  94. digitalWrite(readingLED, LOW);
  95. Serial.print("Verified ID:");
  96. Serial.println(id);
  97. myservo.write(180); // tell servo to go to 0 degrees
  98. digitalWrite(idLED, HIGH);
  99. delay(2000);
  100. digitalWrite(idLED, LOW);
  101. digitalWrite(nonactiveLED, HIGH);
  102. myservo.detach(); // attaches the servo to pin 9
  103. }
  104. else
  105. {
  106. Serial.println("Finger not found");
  107. digitalWrite(deniedLED, HIGH);
  108. delay(2000);
  109. digitalWrite(deniedLED, LOW);
  110. }
  111. // delay(100);
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118. void closeDoor()
  119. {
  120. fps.CaptureFinger(false);
  121. int id = fps.Identify1_N();
  122. if (id <200)
  123. {
  124. myservo.attach(SERVO_PIN); // attaches the servo to pin 9
  125. digitalWrite(nonactiveLED, LOW);
  126. delay(50);
  127. digitalWrite(readingLED, HIGH);
  128. delay(50);
  129. digitalWrite(readingLED, LOW);
  130. Serial.print("Verified ID:");
  131. Serial.println(id);
  132. myservo.write(130); // tell servo to go to 90 degrees
  133. digitalWrite(idLED, HIGH);
  134. delay(2000);
  135. digitalWrite(idLED, LOW);
  136. digitalWrite(nonactiveLED, HIGH);
  137. myservo.detach(); // attaches the servo to pin 9
  138. }
  139. else
  140. {
  141. Serial.println("Finger not found");
  142. digitalWrite(deniedLED, HIGH);
  143. delay(2000);
  144. digitalWrite(deniedLED, LOW);
  145. }
  146. // delay(100);
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement