-
Notifications
You must be signed in to change notification settings - Fork 0
/
fingerAuthServo.cpp
128 lines (115 loc) · 2.56 KB
/
fingerAuthServo.cpp
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
/*
This is a program that rotates the servo motor when the fingerprint authetication is successful.
*/
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include <Servo.h>
#define FINGERPRINT_RX_PIN 18
#define FINGERPRINT_TX_PIN 19
// Servo motor signal pin
#define SERVO_PIN 4
SoftwareSerial fingerSerial(FINGERPRINT_RX_PIN, FINGERPRINT_TX_PIN);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&fingerSerial);
Servo servo;
void setup()
{
Serial.begin(57600);
fingerSerial.begin(57600);
if (finger.verifyPassword())
{
Serial.println("Found fingerprint sensor!");
}
else
{
Serial.println("Did not find fingerprint sensor :(");
while (1)
{
delay(1);
}
}
// connect to signal pin of servo motor
servo.attach(SERVO_PIN);
}
void loop()
{
getFingerprintID();
delay(500);
}
void getFingerprintID()
{
uint8_t p = finger.getImage();
switch (p)
{
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return;
default:
Serial.println("Unknown error");
return;
}
p = finger.image2Tz();
switch (p)
{
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return;
default:
Serial.println("Unknown error");
return;
}
p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK)
{
Serial.println("Finger found!");
// processing to rotate the servo motor
rotateServo();
return;
}
else if (p == FINGERPRINT_PACKETRECIEVEERR)
{
Serial.println("Communication error");
return;
}
else if (p == FINGERPRINT_NOTFOUND)
{
Serial.println("No match found");
return;
}
else
{
Serial.println("Unknown error");
return;
}
}
void rotateServo()
{
// Move the servo motor to 180 degrees(open)
servo.write(180);
// wait 2 seconds
delay(10000);
// Move the servo motor to 90 degrees(close)
servo.write(90);
// wait 2 seconds
delay(2000);
}