• Cititor de amprente • Senzor • Buzzer • Placa Arduino • Servomotor
Cod:
Ultrasonic ultrasonic(A2, 12); A2- trigger, 12- echo Servo myservo; create servo object to control a servo
SoftwareSerial mySerial(2, 3); RX and TX for fingerprint Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); int fingerprintID = 0; 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 ledPin = 5; LED connected to digital pin 5
int previousButtonState, presentButtonState, ledState;
the pin for buzzer int buzzer = 11; </note> Sonerie : <note tip> void buzz_function(){ for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) { stop pressing the button
if(digitalRead(buttonPinAlarm) == LOW){ return; }
// calculates the duration of each note divider = pgm_read_word_near(melody+thisNote + 1); if (divider > 0) { // regular note, just proceed noteDuration = (wholenote) / divider; } else if (divider < 0) { // dotted notes are represented with negative durations!! noteDuration = (wholenote) / abs(divider); noteDuration *= 1.5; // increases the duration in half for dotted notes }
// we only play the note for 90% of the duration, leaving 10% as a pause tone(buzzer, pgm_read_word_near(melody+thisNote), noteDuration * 0.9);
// Wait for the specief duration before playing the next note. delay(noteDuration);
// stop the waveform generation before the next note. noTone(buzzer); }
}
myservo.attach(6); // attaches the servo on pin 9 to the servo object Serial.begin(9600); finger.begin(57600);
pinMode(buttonPinAlarm, INPUT); // Set button pin as input pinMode(ledPin, OUTPUT); // ledPin output pinMode(buttonPinPass, INPUT); previousButtonState = 0; presentButtonState = 0; ledState = LOW; delay(50);
while (!finger.verifyPassword()) { Serial.println("Did not find fingerprint sensor :("); delay(300);
} Serial.println(“Found fingerprint sensor!”);
myservo.write(180);
}
Main function
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(); }
}
#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.