This shows you the differences between two versions of the page.
|
pm:prj2023:abirlica:andreigabriel [2023/05/28 17:42] gabriel.andrei1707 [Software Design] |
pm:prj2023:abirlica:andreigabriel [2023/05/28 17:54] (current) gabriel.andrei1707 [Concluzii] |
||
|---|---|---|---|
| Line 46: | Line 46: | ||
| Ultrasonic ultrasonic(A2, 12); // A2- trigger, 12- echo | Ultrasonic ultrasonic(A2, 12); // A2- trigger, 12- echo | ||
| + | |||
| Servo myservo; // create servo object to control a servo | Servo myservo; // create servo object to control a servo | ||
| + | |||
| SoftwareSerial mySerial(2, 3); // RX and TX for fingerprint | SoftwareSerial mySerial(2, 3); // RX and TX for fingerprint | ||
| + | |||
| Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); | Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); | ||
| - | int val; // variable to read the value from the analog pin | + | |
| int fingerprintID = 0; | int fingerprintID = 0; | ||
| + | |||
| const int buttonPinAlarm = A1; // Button connected to analog pin A1; ring button | const int buttonPinAlarm = A1; // Button connected to analog pin A1; ring button | ||
| + | |||
| const int buttonPinPass = A0; // Button connected to analog pin A1; open/close door button | const int buttonPinPass = A0; // Button connected to analog pin A1; open/close door button | ||
| + | |||
| const int ledPin = 5; // LED connected to digital pin 5 | const int ledPin = 5; // LED connected to digital pin 5 | ||
| Line 115: | Line 121: | ||
| myservo.write(180); | myservo.write(180); | ||
| + | } | ||
| + | </note> | ||
| + | |||
| + | Main function | ||
| + | <note tip> | ||
| + | void loop() { | ||
| + | | ||
| + | previousButtonState = presentButtonState; | ||
| + | presentButtonState = digitalRead(buttonPinPass); | ||
| + | |||
| + | while(ultrasonic.read() < 50 && !ledState){ | ||
| + | tone(buzzer, NOTE_D8, 10); // alarm on | ||
| + | delay(50); | ||
| + | } | ||
| + | |||
| + | if(previousButtonState == HIGH && presentButtonState == LOW) {/* if the previous state is the HIGH and present state is LOW then */ | ||
| + | int found = 1; | ||
| + | |||
| + | while(finger.getImage() != FINGERPRINT_OK && ledState != HIGH){ | ||
| + | previousButtonState = presentButtonState; | ||
| + | presentButtonState = digitalRead(buttonPinPass); | ||
| + | if(previousButtonState == HIGH && presentButtonState == LOW) { | ||
| + | found = 0; | ||
| + | break; | ||
| + | } | ||
| + | delay(100); | ||
| + | |||
| + | } | ||
| + | | ||
| + | if(found){ | ||
| + | // found a match! | ||
| + | Serial.print("Found ID #"); | ||
| + | Serial.print(finger.fingerID); | ||
| + | |||
| + | ledState = !ledState; // change the state of the LED | ||
| + | |||
| + | digitalWrite(ledPin, ledState); /* write that changed state to the LED */ | ||
| + | |||
| + | // move the servo | ||
| + | if(ledState){ | ||
| + | // open door | ||
| + | for (int pos = 180; pos >= 90; pos -= 1) { | ||
| + | myservo.write(pos); | ||
| + | delay(15); | ||
| + | } | ||
| + | } | ||
| + | else{ | ||
| + | // close door | ||
| + | for (int pos = 90; pos <= 180; pos += 1) { | ||
| + | myservo.write(pos); | ||
| + | delay(15); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | // play song | ||
| + | if(digitalRead(buttonPinAlarm) == HIGH){ | ||
| + | buzz_function(); | ||
| + | } | ||
| + | | ||
| } | } | ||
| </note> | </note> | ||
| Line 123: | Line 191: | ||
| </note> | </note> | ||
| + | <note tip> | ||
| + | Pentru realizarea proiectului am folosit urmatoarele biblioteci: | ||
| + | #include <Adafruit_Fingerprint.h> | ||
| + | |||
| + | #include <Servo.h> | ||
| + | |||
| + | #include <Ultrasonic.h> | ||
| + | |||
| + | |||
| + | Am conectat senzorul fingerprint la pinii care permit comunicarea cu placa Arduino. | ||
| + | Servo motorul deschide si inchide usa de carton. | ||
| + | </note> | ||
| ===== Download ===== | ===== Download ===== | ||
| <note warning> | <note warning> | ||
| + | |||
| + | |||
| + | |||
| + | https://github.com/GabrielAndrei17/Proiect-PM | ||
| </note> | </note> | ||