Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_Fingerprint.h>
- #include <SoftwareSerial.h>
- SoftwareSerial mySerial(2, 3); // rx, tx
- Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
- const byte R_ON = 16;
- const byte R_ALARM = 17;
- int control = 0;
- int count = 0;
- void relay_control();
- #define LIMIT 3
- #define BENAR 1
- #define SALAH 2
- void setup()
- {
- pinMode(R_ON, OUTPUT);
- pinMode(R_ALARM, OUTPUT);
- digitalWrite(R_ON, LOW); // mematikan relay
- digitalWrite(R_ALARM, LOW); // mematikan ALARM
- Serial.begin(9600); // setting kecepatan transfer komunikasi serial
- while (!Serial);
- delay(100); //tunda waktu selama 1/10 detik
- Serial.println("\n\nAdafruit finger detect test");
- // set the data rate for the sensor serial port
- finger.begin(57600);
- if (finger.verifyPassword()) { // jika
- Serial.println("Found fingerprint sensor!");
- } else {
- Serial.println("Did not find fingerprint sensor :(");
- while (1) { delay(1); }
- }
- finger.getTemplateCount();
- Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
- Serial.println("Waiting for valid finger...");
- }
- void loop() // run over and over again
- {
- //getFingerprintIDez();
- getFingerprintID();
- relay_control(); // CEK control relay
- delay(100); //don't ned to run this at full speed.
- }
- uint8_t getFingerprintID() {
- uint8_t p = finger.getImage();
- switch (p) {
- case FINGERPRINT_OK:
- Serial.println("Image taken"); // jika di tempel sidik jari
- break;
- case FINGERPRINT_NOFINGER:
- Serial.println("No finger detected"); // tidak di tempel sidik jari
- return p;
- case FINGERPRINT_PACKETRECIEVEERR:
- Serial.println("Communication error");
- return p;
- case FINGERPRINT_IMAGEFAIL:
- Serial.println("Imaging error");
- return p;
- default:
- Serial.println("Unknown error");
- return p;
- }
- // OK success!
- p = finger.image2Tz();
- switch (p) {
- case FINGERPRINT_OK:
- Serial.println("Image converted");
- break;
- case FINGERPRINT_IMAGEMESS:
- Serial.println("Image too messy");
- return p;
- case FINGERPRINT_PACKETRECIEVEERR:
- //Serial.println("Communication error");
- return p;
- case FINGERPRINT_FEATUREFAIL:
- //Serial.println("Could not find fingerprint features");
- return p;
- case FINGERPRINT_INVALIDIMAGE:
- //Serial.println("Could not find fingerprint features");
- return p;
- default:
- Serial.println("Unknown error");
- return p;
- }
- // OK converted!
- p = finger.fingerFastSearch();
- if (p == FINGERPRINT_OK) {
- Serial.println("Found a print match!"); // jika di tempel sidika jari dan sidik jari terdaftar
- control = 1;
- } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
- //Serial.println("Communication error");
- return p;
- } else if (p == FINGERPRINT_NOTFOUND) {
- Serial.println("Did not find a match"); // di tempel tapi tidak ada terdaftar sidik jari
- control = 2;
- count = count + 1;
- Serial.println(control);
- return p;
- } else {
- Serial.println("Unknown error");
- return p;
- }
- // found a match!
- Serial.print("Found ID #"); Serial.print(finger.fingerID);
- Serial.print(" with confidence of "); Serial.println(finger.confidence);
- return finger.fingerID;
- }
- // returns -1 if failed, otherwise returns ID #
- int getFingerprintIDez() {
- uint8_t p = finger.getImage();
- if (p != FINGERPRINT_OK) return -1;
- p = finger.image2Tz();
- if (p != FINGERPRINT_OK) return -1;
- p = finger.fingerFastSearch();
- if (p != FINGERPRINT_OK) return -1;
- // found a match!
- Serial.print("Found ID #"); Serial.print(finger.fingerID);
- Serial.print(" with confidence of "); Serial.println(finger.confidence);
- return finger.fingerID;
- }
- void relay_control(){
- if ( control == BENAR ){
- digitalWrite(R_ON, HIGH); // relay di on kan --> MOTOR HIDUP
- digitalWrite(R_ALARM, LOW); // --> ALARM MATI
- }
- else if ( control == SALAH ){
- digitalWrite(R_ON, LOW); // ---> MOTOR MATI
- Serial.println(count);
- if ( count == LIMIT){
- digitalWrite(R_ALARM, HIGH); //---> ALARM HIDUP SETELAH LIMIT
- }
- else{
- digitalWrite(R_ALARM, LOW);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement