SlideShare a Scribd company logo
////Arduino libraries
#include <avr/sleep.h>
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include <TimerObject.h>
//Camera and SD card
#include <Adafruit_VC0706.h>
#include <SPI.h>
#include <SD.h>
SoftwareSerial cameraconnection = SoftwareSerial(69, 3);
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);
#define chipSelect 53
#define door
//NFC
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
#define IRQ (22)
#define RESET (24) // Not connected by default on the NFC Shield
Adafruit_NFCShield_I2C nfc(IRQ, RESET);
unsigned long tag = 2763526164;
int motor[] = {4, 5};
int ledPin = 13;
int pirState = 0;
int pirPin = 21;
int reedState = 0;
int reedPin = 6;
int doorState;
int counter =0;
int timer = millis();
int fpPin = 12;
int fpsave = LOW;
int nfccounter = 0;
boolean success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes
depending on ISO14443A card type)
TimerObject *timer1 = new TimerObject(20000);
TimerObject *timer2 = new TimerObject(5000);
int getFingerprintIDez();
SoftwareSerial mySerial(10,11);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
void setup()
{
//attachInterrupt(5,wakeUpNow, LOW);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
/////////////NFC
Serial.begin(115200);
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF,
HEX);
nfc.setPassiveActivationRetries(0x01);
// configure board to read RFID tags
nfc.SAMConfig();
//Serial.begin(9600);
pinMode(53, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
pinMode(reedPin, INPUT);
finger.begin(57600);
timer1->setOnTimer(MCUsleep);
timer2->setOnTimer(Picture);
int i;
for(i = 0; i < 2; i++){
pinMode(motor[i], OUTPUT);
}
}
void loop()
{
nfc.begin();
Serial.print("ddddddddddddd");
doorState = LOW;
///Open state function
Open();
///Closed State function
Close();
timer1->Start();
timer2->Start();
///Checks the magenetic reed switch to see if the door is open or closed
reedState=digitalRead(reedPin);
while(reedState == HIGH && doorState == LOW)
{
digitalWrite(13, HIGH);
if(counter == 1)
{
Serial.print("Stop");
///takes a picture after 5 seconds
timer2->setOnTimer(Picture);
//prevents the counter from reseting
timer2->Stop();
}
///checks magnetic reed switch to see if some one has opened the door
reedState=digitalRead(reedPin);
///Finger print confirmation to unlock the door
getFingerprintIDez();
///NFC confermation to unlock the door
NFCcon();
nfccounter=0;
Serial.println("waiting");
Serial.println(counter);
timer1->Update();
timer2->Update();
}
timer1->Stop();
Open();
Close();
}
///Open door function to prevent the microcontroller from falling asleep
void Open()
{
reedState=digitalRead(reedPin);
while(reedState == LOW)
{
doorState = HIGH;
reedState=digitalRead(reedPin);
delay(500);
Serial.println("Open");
}
}
///Locks the door when the door is closed from an open state
void Close()
{
reedState=digitalRead(reedPin);
if(reedState==HIGH && doorState == HIGH)
{
Lock();
reedState=digitalRead(reedPin);
Serial.println("Close");
// delay(1000);
MCUsleep();
}
}
///NFC confirmation function
void NFCcon()
{
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
if (nfccounter==0)
{
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLeng
th);
uint32_t cardidentifier = 0;
if (success) {
// Display some basic information about the card
//Serial.println("Found an ISO14443A card");
//Serial.println("Card detected #");
// turn the four byte UID of a mifare classic into a single variable #
cardidentifier = uid[3];
cardidentifier <<= 8; cardidentifier |= uid[2];
cardidentifier <<= 8; cardidentifier |= uid[1];
cardidentifier <<= 8; cardidentifier |= uid[0];
//Serial.println(cardidentifier);
if (cardidentifier == tag) {
Unlock();
Serial.println("It's a match");
timer2->Stop();
}
else {
Serial.println("It's not a match");
}
Serial.println("");
}
nfccounter = 1;
}
}
/// Tell the camera to take a picture
void Picture()
{
Serial.println("VC0706 Camera snapshot test");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
// return;
}
// Try to locate the camera
if (cam.begin()) {
Serial.println("Camera Found:");
} else {
Serial.println("No camera found?");
// return;
}
cam.setImageSize(VC0706_320x240); // biggest
Serial.println("Snap in 1 secs...");
// delay(1000);
if (! cam.takePicture())
Serial.println("Failed to snap!");
else
Serial.println("Picture taken!");
// Create an image with the name IMAGExx.JPG
char filename[13];
strcpy(filename, "IMAGE00.JPG");
for (int i = 0; i < 100; i++) {
filename[5] = '0' + i/10;
filename[6] = '0' + i%10;
// create if does not exist, do not open existing, write, sync after
write
if (! SD.exists(filename)) {
break;
}
}
// Open the file for writing
File imgFile = SD.open(filename, FILE_WRITE);
// Get the size of the image (frame) taken
uint16_t jpglen = cam.frameLength();
Serial.print("Storing ");
Serial.print(jpglen, DEC);
Serial.print(" byte image.");
int32_t time = millis();
pinMode(8, OUTPUT);
// Read all the data up to # bytes!
byte wCount = 0; // For counting # of writes
while (jpglen > 0) {
// read 32 bytes at a time;
uint8_t *buffer;
uint8_t bytesToRead = min(64, jpglen); // change 32 to 64 for a speedup
but may not work with all setups!
buffer = cam.readPicture(bytesToRead);
imgFile.write(buffer, bytesToRead);
if(++wCount >= 64) { // Every 2K, give a little feedback so it doesn't
appear locked up
Serial.print('.');
wCount = 0;
}
//Serial.print("Read "); Serial.print(bytesToRead, DEC);
Serial.println(" bytes");
jpglen -= bytesToRead;
}
imgFile.close();
time = millis() - time;
counter = 1;
Serial.println("done!");
Serial.print(time); Serial.println(" ms elapsed");
//return;
}
//FingerPrint confirmation function
int getFingerprintIDez() {
finger.begin(57600);
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!
//Picture();
counter = 1;
Unlock();
Serial.println("FIngerprint");
return finger.fingerID;
}
/// tells the door the lock by setting the motor driver polarity
void Lock()
{
Serial.print("Lock");
digitalWrite(motor[0], LOW);
digitalWrite(motor[1], HIGH);
//digitalWrite(13, HIGH);
delay(1500);
digitalWrite(motor[0], LOW);
digitalWrite(motor[1], LOW);
//digitalWrite(13, LOW);
}
///Unlocks the door by setting the motor driver polarity
void Unlock()
{
timer2->Stop();
Serial.print("Unlock");
digitalWrite(motor[0], HIGH);
digitalWrite(motor[1], LOW);
//digitalWrite(13, HIGH);
delay(1500);
digitalWrite(motor[0], LOW);
digitalWrite(motor[1], LOW);
//digitalWrite(13, LOW);
}
/// function to Wake the microcontroller up from sleep
void wakeUpNow()
{
timer1->Start();
timer2->Start();
}
///function for microcontroller to go to sleep
void MCUsleep()
{
Serial.println("Sleep");
delay(300);
counter = 0;
Serial.println(counter);
digitalWrite(13, LOW);
;
delay(500);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
attachInterrupt(5,wakeUpNow, LOW);
sleep_mode();
detachInterrupt(5);
}

More Related Content

PDF
망고100 보드로 놀아보자 15
PDF
DEF CON 24 - Patrick Wardle - 99 problems little snitch
PDF
Android 4.2 Internals - Bluetooth and Network
DOCX
codings related to avr micro controller
PPTX
Embedded JavaScript
PDF
NYU hacknight, april 6, 2016
PDF
Sniffing Mach Messages
PDF
The true story_of_hello_world
망고100 보드로 놀아보자 15
DEF CON 24 - Patrick Wardle - 99 problems little snitch
Android 4.2 Internals - Bluetooth and Network
codings related to avr micro controller
Embedded JavaScript
NYU hacknight, april 6, 2016
Sniffing Mach Messages
The true story_of_hello_world

What's hot (20)

PPT
W8_2: Inside the UoS Educational Processor
PDF
Moony li pacsec-1.8
PDF
Kernel entrance to-geek-
PDF
Html5 game, websocket e arduino
ODP
Sysprog 12
ODP
Sysprog 12
PPT
Linoma CryptoComplete
PDF
Optimizing GELI Performance by John-Mark Gurney
PDF
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
PDF
Geth important commands
PDF
JJUG CCC 2018 Spring - I-7 (俺が)はじめての Netty
PDF
Arduino shield wifi-monitorizarelocuinta
PDF
Keyless Door Entry via Bluetooth Technology
PPT
Formatul Portable Executable
PDF
The Ring programming language version 1.5.3 book - Part 97 of 184
PPSX
Processor 01 presentation
PDF
Live Updating Swift Code
PDF
Orasta500.c
PDF
[DefCon 2016] I got 99 Problems, but 
Little Snitch ain’t one!
PDF
Apache Wicket and Java EE sitting in a tree
W8_2: Inside the UoS Educational Processor
Moony li pacsec-1.8
Kernel entrance to-geek-
Html5 game, websocket e arduino
Sysprog 12
Sysprog 12
Linoma CryptoComplete
Optimizing GELI Performance by John-Mark Gurney
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
Geth important commands
JJUG CCC 2018 Spring - I-7 (俺が)はじめての Netty
Arduino shield wifi-monitorizarelocuinta
Keyless Door Entry via Bluetooth Technology
Formatul Portable Executable
The Ring programming language version 1.5.3 book - Part 97 of 184
Processor 01 presentation
Live Updating Swift Code
Orasta500.c
[DefCon 2016] I got 99 Problems, but 
Little Snitch ain’t one!
Apache Wicket and Java EE sitting in a tree
Ad

Viewers also liked (18)

PDF
Greenworks Linkedin Portfolio
PPTX
how to export a product
PDF
LFZH Final Report
PDF
REAM x GE Productive End-Use of MHP 28FEB16
PPTX
my last vacation
PDF
Robert Resume 8-26-15
PPTX
Bodega marqués de riscal
PDF
Acabecadestevejobs 091230131636-phpapp01
PPTX
LFZH Final Presentation
PPTX
HOW TO EXPORT A PRODUCT
PPTX
Red lions futbol
PPTX
Visa application thailand
PDF
Muhammad_Aslam_CV
DOCX
Artificial Implants and the Field of Visual Prosthesis Research Paper
PPTX
Carbon and its structure
PPTX
Artificial Implants and the Field of Visual Prosthesis
DOCX
ABJ Biochemistry Manuscript
PPTX
Models of teaching and learning
Greenworks Linkedin Portfolio
how to export a product
LFZH Final Report
REAM x GE Productive End-Use of MHP 28FEB16
my last vacation
Robert Resume 8-26-15
Bodega marqués de riscal
Acabecadestevejobs 091230131636-phpapp01
LFZH Final Presentation
HOW TO EXPORT A PRODUCT
Red lions futbol
Visa application thailand
Muhammad_Aslam_CV
Artificial Implants and the Field of Visual Prosthesis Research Paper
Carbon and its structure
Artificial Implants and the Field of Visual Prosthesis
ABJ Biochemistry Manuscript
Models of teaching and learning
Ad

Similar to Arduino (20)

DOCX
Fingerprint base security system
TXT
Samrt attendance system using fingerprint
DOCX
Solution doc
PDF
Fingerprint base security system
PPTX
Fingerprint Based Security System
PDF
Real time model of a lock gate system upon fingerprint with microcontroller
PPTX
ppt2 (1).pptx
PPTX
Magnetic door lock using arduino
PPTX
Fingerprint base security system
DOC
Fingerprint based physical access control vehicle immobilizer
PPTX
finger print based door lock.pptx
DOC
Fingerprint based security system
PPTX
Project_updated
PPTX
FINGERPRINT BASED VEHICLE STARTER . USING AURDINO
PPTX
Smart vault ppt
PDF
vensoft technologies http://www.ieeedeveloperslabs.in/ finger print based at...
PDF
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
PDF
Embedded systemsproject_2020
PPTX
FINGERPRINT DOORLOCK USING ARDUINO UNO _
PPTX
An Introduction to Microcontrollers part 2
Fingerprint base security system
Samrt attendance system using fingerprint
Solution doc
Fingerprint base security system
Fingerprint Based Security System
Real time model of a lock gate system upon fingerprint with microcontroller
ppt2 (1).pptx
Magnetic door lock using arduino
Fingerprint base security system
Fingerprint based physical access control vehicle immobilizer
finger print based door lock.pptx
Fingerprint based security system
Project_updated
FINGERPRINT BASED VEHICLE STARTER . USING AURDINO
Smart vault ppt
vensoft technologies http://www.ieeedeveloperslabs.in/ finger print based at...
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
Embedded systemsproject_2020
FINGERPRINT DOORLOCK USING ARDUINO UNO _
An Introduction to Microcontrollers part 2

Arduino

  • 1. ////Arduino libraries #include <avr/sleep.h> #include <Adafruit_Fingerprint.h> #include <SoftwareSerial.h> #include <TimerObject.h> //Camera and SD card #include <Adafruit_VC0706.h> #include <SPI.h> #include <SD.h> SoftwareSerial cameraconnection = SoftwareSerial(69, 3); Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection); #define chipSelect 53 #define door //NFC #include <Wire.h> #include <Adafruit_NFCShield_I2C.h> #define IRQ (22) #define RESET (24) // Not connected by default on the NFC Shield Adafruit_NFCShield_I2C nfc(IRQ, RESET); unsigned long tag = 2763526164; int motor[] = {4, 5}; int ledPin = 13; int pirState = 0; int pirPin = 21; int reedState = 0; int reedPin = 6; int doorState; int counter =0; int timer = millis(); int fpPin = 12; int fpsave = LOW; int nfccounter = 0; boolean success; uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type) TimerObject *timer1 = new TimerObject(20000); TimerObject *timer2 = new TimerObject(5000); int getFingerprintIDez(); SoftwareSerial mySerial(10,11); Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); void setup() { //attachInterrupt(5,wakeUpNow, LOW); pinMode(13, OUTPUT); digitalWrite(13, HIGH); /////////////NFC Serial.begin(115200);
  • 2. nfc.begin(); uint32_t versiondata = nfc.getFirmwareVersion(); if (! versiondata) { Serial.print("Didn't find PN53x board"); while (1); // halt } Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); nfc.setPassiveActivationRetries(0x01); // configure board to read RFID tags nfc.SAMConfig(); //Serial.begin(9600); pinMode(53, OUTPUT); pinMode(ledPin, OUTPUT); pinMode(pirPin, INPUT); pinMode(reedPin, INPUT); finger.begin(57600); timer1->setOnTimer(MCUsleep); timer2->setOnTimer(Picture); int i; for(i = 0; i < 2; i++){ pinMode(motor[i], OUTPUT); } } void loop() { nfc.begin(); Serial.print("ddddddddddddd"); doorState = LOW; ///Open state function Open(); ///Closed State function Close(); timer1->Start(); timer2->Start(); ///Checks the magenetic reed switch to see if the door is open or closed reedState=digitalRead(reedPin); while(reedState == HIGH && doorState == LOW) { digitalWrite(13, HIGH); if(counter == 1) {
  • 3. Serial.print("Stop"); ///takes a picture after 5 seconds timer2->setOnTimer(Picture); //prevents the counter from reseting timer2->Stop(); } ///checks magnetic reed switch to see if some one has opened the door reedState=digitalRead(reedPin); ///Finger print confirmation to unlock the door getFingerprintIDez(); ///NFC confermation to unlock the door NFCcon(); nfccounter=0; Serial.println("waiting"); Serial.println(counter); timer1->Update(); timer2->Update(); } timer1->Stop(); Open(); Close(); } ///Open door function to prevent the microcontroller from falling asleep void Open() { reedState=digitalRead(reedPin); while(reedState == LOW) { doorState = HIGH; reedState=digitalRead(reedPin); delay(500); Serial.println("Open"); } } ///Locks the door when the door is closed from an open state void Close() { reedState=digitalRead(reedPin); if(reedState==HIGH && doorState == HIGH) { Lock();
  • 4. reedState=digitalRead(reedPin); Serial.println("Close"); // delay(1000); MCUsleep(); } } ///NFC confirmation function void NFCcon() { // Wait for an ISO14443A type cards (Mifare, etc.). When one is found // 'uid' will be populated with the UID, and uidLength will indicate // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight) if (nfccounter==0) { success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLeng th); uint32_t cardidentifier = 0; if (success) { // Display some basic information about the card //Serial.println("Found an ISO14443A card"); //Serial.println("Card detected #"); // turn the four byte UID of a mifare classic into a single variable # cardidentifier = uid[3]; cardidentifier <<= 8; cardidentifier |= uid[2]; cardidentifier <<= 8; cardidentifier |= uid[1]; cardidentifier <<= 8; cardidentifier |= uid[0]; //Serial.println(cardidentifier); if (cardidentifier == tag) { Unlock(); Serial.println("It's a match"); timer2->Stop(); } else { Serial.println("It's not a match"); } Serial.println(""); } nfccounter = 1; } } /// Tell the camera to take a picture void Picture() { Serial.println("VC0706 Camera snapshot test"); // see if the card is present and can be initialized:
  • 5. if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); // don't do anything more: // return; } // Try to locate the camera if (cam.begin()) { Serial.println("Camera Found:"); } else { Serial.println("No camera found?"); // return; } cam.setImageSize(VC0706_320x240); // biggest Serial.println("Snap in 1 secs..."); // delay(1000); if (! cam.takePicture()) Serial.println("Failed to snap!"); else Serial.println("Picture taken!"); // Create an image with the name IMAGExx.JPG char filename[13]; strcpy(filename, "IMAGE00.JPG"); for (int i = 0; i < 100; i++) { filename[5] = '0' + i/10; filename[6] = '0' + i%10; // create if does not exist, do not open existing, write, sync after write if (! SD.exists(filename)) { break; } } // Open the file for writing File imgFile = SD.open(filename, FILE_WRITE); // Get the size of the image (frame) taken uint16_t jpglen = cam.frameLength(); Serial.print("Storing "); Serial.print(jpglen, DEC); Serial.print(" byte image."); int32_t time = millis(); pinMode(8, OUTPUT); // Read all the data up to # bytes! byte wCount = 0; // For counting # of writes while (jpglen > 0) { // read 32 bytes at a time;
  • 6. uint8_t *buffer; uint8_t bytesToRead = min(64, jpglen); // change 32 to 64 for a speedup but may not work with all setups! buffer = cam.readPicture(bytesToRead); imgFile.write(buffer, bytesToRead); if(++wCount >= 64) { // Every 2K, give a little feedback so it doesn't appear locked up Serial.print('.'); wCount = 0; } //Serial.print("Read "); Serial.print(bytesToRead, DEC); Serial.println(" bytes"); jpglen -= bytesToRead; } imgFile.close(); time = millis() - time; counter = 1; Serial.println("done!"); Serial.print(time); Serial.println(" ms elapsed"); //return; } //FingerPrint confirmation function int getFingerprintIDez() { finger.begin(57600); 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! //Picture(); counter = 1; Unlock(); Serial.println("FIngerprint"); return finger.fingerID; } /// tells the door the lock by setting the motor driver polarity void Lock() { Serial.print("Lock"); digitalWrite(motor[0], LOW); digitalWrite(motor[1], HIGH); //digitalWrite(13, HIGH);
  • 7. delay(1500); digitalWrite(motor[0], LOW); digitalWrite(motor[1], LOW); //digitalWrite(13, LOW); } ///Unlocks the door by setting the motor driver polarity void Unlock() { timer2->Stop(); Serial.print("Unlock"); digitalWrite(motor[0], HIGH); digitalWrite(motor[1], LOW); //digitalWrite(13, HIGH); delay(1500); digitalWrite(motor[0], LOW); digitalWrite(motor[1], LOW); //digitalWrite(13, LOW); } /// function to Wake the microcontroller up from sleep void wakeUpNow() { timer1->Start(); timer2->Start(); } ///function for microcontroller to go to sleep void MCUsleep() { Serial.println("Sleep"); delay(300); counter = 0; Serial.println(counter); digitalWrite(13, LOW); ; delay(500); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_enable(); attachInterrupt(5,wakeUpNow, LOW); sleep_mode(); detachInterrupt(5); }