microrobotics

R503 Fingerprint Sensor LED Control

Aug 5th, 2021 (edited)
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_Fingerprint.h>
  2.  
  3. #if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
  4. // For UNO and others without hardware serial, we must use software serial...
  5. // pin #2 is IN from sensor (YELLOW wire)
  6. // pin #3 is OUT from arduino  (GREEN)
  7. // Set up the serial port to use softwareserial..
  8. SoftwareSerial mySerial(2, 3);
  9.  
  10. #else
  11. // On Leonardo/M0/etc, others with hardware serial, use hardware serial!
  12. #define mySerial Serial1
  13.  
  14. #endif
  15.  
  16. Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
  17.  
  18. void setup()
  19. {
  20.   Serial.begin(9600);
  21.   while (!Serial);  // For Yun/Leo/Micro/Zero/...
  22.   delay(100);
  23.   Serial.println("\n\nAdafruit finger detect test");
  24.  
  25.   // set the data rate for the sensor serial port
  26.   finger.begin(57600);
  27.   delay(5);
  28.   if (finger.verifyPassword()) {
  29.     Serial.println("Found fingerprint sensor!");
  30.   } else {
  31.     Serial.println("Did not find fingerprint sensor :(");
  32.     while (1) { delay(1); }
  33.   }
  34.  
  35.   Serial.println(F("Reading sensor parameters"));
  36.   finger.getParameters();
  37.   Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX);
  38.   Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
  39.   Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
  40.   Serial.print(F("Security level: ")); Serial.println(finger.security_level);
  41.   Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX);
  42.   Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
  43.   Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);
  44.  
  45.  
  46. }
  47.  
  48. void loop()                     // run over and over again
  49. {
  50.   // LED fully on
  51.   finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_RED);
  52.   delay(250);
  53.   finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_BLUE);
  54.   delay(250);
  55.   finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_PURPLE);
  56.   delay(250);
  57.  
  58.   // flash red LED
  59.   finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_RED, 10);
  60.   delay(2000);
  61.   // Breathe blue LED till we say to stop
  62.   finger.LEDcontrol(FINGERPRINT_LED_BREATHING, 100, FINGERPRINT_LED_BLUE);
  63.   delay(3000);
  64.   finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_ON, 200, FINGERPRINT_LED_PURPLE);
  65.   delay(2000);
  66.   finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_OFF, 200, FINGERPRINT_LED_PURPLE);
  67.   delay(2000);
  68. }
Add Comment
Please, Sign In to add comment