Project 3 TLI-31300
Bar graph with LEDs and potentiometer using an analog into convert to a digital 4 byte integer for PWM control.
Components and supplies
9
LED (generic)
9
Arduino UNO
1
FInger print scanner
1
Resistor 100k ohm
1
Rotary potentiometer (generic)
Project description
Code
TLI-31300
c_cpp
Comments in code
1 2/* 3 Casey Fulford Biometrics TLI 31300 4 Project 3 - Bar Graph with Potentiometer 5 For this I used a fingerprint scanner to turn on the light program 6 Need to register fingerprints with the Adafruit Enroll program 7 8 */ 9 10#include <Adafruit_Fingerprint.h> 11#include <SoftwareSerial.h> 12 13SoftwareSerial mySerial(2, 3); 14Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); 15 16int fingerprintID = 0; // Set this to 0 for a place holder 17 18int getFingerprintIDez(); // Function declaraton. This calls the get.finger object from the Adafruit library 19const int potPin = A0; // Analog input pin connected to the potentiometer 20int potValue = 0; // Value that will be read from the potentiometer 21const int ledCount = 9; 22int ledPins[] = {2,3,4,5,6,7,8,9,10}; 23boolean mainUser; // This is a true / false for showing the main user 24 25 26void setup() 27{ 28 for (int thisLed = 0; thisLed < ledCount; thisLed++) 29 { 30 pinMode(ledPins[thisLed], OUTPUT); // Set the LED pins as output 31 } 32 Serial.begin(9600); 33 while (!Serial); // For Yun/Leo/Micro/Zero/... 34 delay(100); 35 Serial.println("\ 36\ 37Adafruit finger detect test"); 38 39 // set the data rate for the sensor serial port 40 finger.begin(57600); 41 42 if (finger.verifyPassword()) { 43 Serial.println("Found fingerprint sensor!"); 44 } else { 45 Serial.println("Did not find fingerprint sensor :("); 46 while (1) { delay(1); } 47 } 48 49 finger.getTemplateCount(); 50 Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates"); 51 Serial.println("Waiting for valid finger..."); 52} 53 54 55void loop() 56 57{ 58 fingerprintID = getFingerprintIDez(); 59 delay(50); 60 if (fingerprintID == 1) 61 { 62 63 mainUser = true; 64 } 65 else if (fingerprintID != 1) 66 { 67 mainUser = false; 68 } 69 while (mainUser) 70 { 71 int sensorReading = analogRead(analogPin); // Analog input 72 int ledLevel = map(sensorReading, 0, 1023, 0, ledCount); 73 for (int thisLed = 0; thisLed < ledCount; thisLed++) 74 { 75 if (thisLed < ledLevel) 76 { 77 digitalWrite(ledPins[thisLed], HIGH); 78 } 79 else 80 { // Turn off LEDs in sequence 81 digitalWrite(ledPins[thisLed], LOW); 82 } 83} 84 } 85 86 if (mainUser = false) 87 { 88 digitalWrite(buzzerPin, HIGH); // Send potentiometer value to LED 89 digitalWrite(errorPin, HIGH); // Send potentiometer value to LED 90 delay(500); 91 92 } 93} // end of main 94 95// returns -1 if failed, otherwise returns ID # 96int getFingerprintIDez() { 97 uint8_t p = finger.getImage(); 98 if (p != FINGERPRINT_OK) return -1; 99 100 p = finger.image2Tz(); 101 if (p != FINGERPRINT_OK) return -1; 102 103 p = finger.fingerFastSearch(); 104 if (p != FINGERPRINT_OK) return -1; 105 106 // found a match! 107 Serial.print("Found ID #"); Serial.print(finger.fingerID); 108 Serial.print(" with confidence of "); Serial.println(finger.confidence); 109 return finger.fingerID; 110} 111 112
Comments
Only logged in users can leave comments