-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLockScan.ino
More file actions
160 lines (122 loc) · 4.05 KB
/
LockScan.ino
File metadata and controls
160 lines (122 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
|----------- FPS Wiring -----------|
|Pin 1: TX (black wire) |
|Pin 2: RX (first white wire) |
|Pin 3: Ground (second white wire) |
|Pin 4: 5V (third white wire) |
|----------------------------------|
Version 1.0: Created by Ryan Westcott, January 12th 2015
Version 2.0: Created by Ryan Westcott, September 26th 2016
Licensed for non-commercial use, must include this license message.
Basically, Feel free to hack away at it, but just give me credit for my work.
Hookup:
arduino tx - 560ohm resistor fps rx - 1000ohm resistor - ground
2: Left Button
3: Right Button
4: FPS
5: FPS
6: Servo
7: Lights
8: Buzzer
*/
#include "FPS_GT511C3.h" //The FPS library
#include "SoftwareSerial.h" //Another needed library
#include <Servo.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
//For the NeoPixel:
#define LEDPin 7
#define NUMPIXELS 24
FPS_GT511C3 fps(4, 5);// The FPS object and it's pins 4 = FPS tx, 5 = FPS rx
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, LEDPin, NEO_GRB + NEO_KHZ800);
Servo lockServo, doorServo;
const int btn01 = 2; // Left (01) button pin
const int btn02 = 3; // Right (02) button pin
const int lockServoPin = 6; // The servo to lock/unlock the door
const int doorServoPin = 7; // The servo to push the door open
const int buzzer = 8; // The pin for a buzzer to provide audible feedback
const int debugLED = 13; // Debug LED used for providing diagnostic feedback
// Lock Servo: used for locking/unlocking the door.
const int unlocked = 180; // The lock servo's position for unlocked
const int locked = 0; // The lock servo's position for locked
// Door Servo: used for magicly pushing the door open
const int doorPosClosed = 0; // The door servo position for closed
const int doorPosOpen = 180; // The door servo position for closed
void setup() {
// Initiate pin inputs/outputs:
pinMode(btn01, INPUT);
pinMode(btn02, INPUT);
pinMode(debugLED, OUTPUT);
digitalWrite(debugLED, LOW); // debugLED is used to show information when the device is in use
fps.UseSerialDebug = false; // no serial, so not needed
fps.Open(); // Connect the FPS
fps.SetLED(true); // Turn on the FPS's LED
// NeoPixel Library code startup code
pixels.begin();
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 3));
pixels.setPixelColor(NUMPIXELS - i, pixels.Color(0, 0, 3));
pixels.show();
delay(30);
}
// lockServo is a servo to open/close the lock:
lockServo.attach(lockServoPin);
lockServo.write(locked);
doorServo.attach(doorServoPin);
doorServo.write(doorPosClosed);
}
void loop() {
if (fps.IsPressFinger()) {
fps.CaptureFinger(false);
int id = fps.Identify1_N();
if (id < 200) {
if (id == 0) {
success();
}
// add the option for other fingers to be scanned here
} else {
fail();
}
} else {
lockServo.write(locked);
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 3));
pixels.setPixelColor(NUMPIXELS - i, pixels.Color(0, 0, 3));
pixels.show();
delay(30);
}
}
}
void success() { // What to do to open the lock:
lockServo.write(unlocked);
doorServo.write(doorPosOpen);
tone(buzzer,800,500);
for (int i = 0; i < NUMPIXELS/2+1; i++) {
pixels.setPixelColor(i, pixels.Color(0, 4, 0));
pixels.setPixelColor(NUMPIXELS - i, pixels.Color(0, 4, 0));
pixels.show();
delay(30);
}
digitalWrite(debugLED, HIGH);
delay(1000);
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 3));
pixels.setPixelColor(NUMPIXELS - i, pixels.Color(0, 0, 3));
pixels.show();
delay(30);
}
}
void fail() {
lockServo.write(unlocked);
doorServo.write(doorPosClosed);
tone(buzzer, 100,700);
for (int i = 0; i < NUMPIXELS/2+1; i++) {
pixels.setPixelColor(i, pixels.Color(4, 0, 0));
pixels.setPixelColor(NUMPIXELS - i, pixels.Color(4, 0, 0));
pixels.show();
delay(30);
}
delay(500);
}