SlideShare a Scribd company logo
1 of 7
Download to read offline
////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

What's hot

Linoma CryptoComplete
Linoma CryptoCompleteLinoma CryptoComplete
Linoma CryptoComplete
Stuart Marsh
 
Arduino shield wifi-monitorizarelocuinta
Arduino shield wifi-monitorizarelocuintaArduino shield wifi-monitorizarelocuinta
Arduino shield wifi-monitorizarelocuinta
Iulius Bors
 
Formatul Portable Executable
Formatul Portable Executable Formatul Portable Executable
Formatul Portable Executable
DefCamp
 

What's hot (20)

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

Viewers also liked

Greenworks Linkedin Portfolio
Greenworks Linkedin PortfolioGreenworks Linkedin Portfolio
Greenworks Linkedin Portfolio
Iain Milroy
 
REAM x GE Productive End-Use of MHP 28FEB16
REAM x GE Productive End-Use of MHP 28FEB16REAM x GE Productive End-Use of MHP 28FEB16
REAM x GE Productive End-Use of MHP 28FEB16
Patrick James Pawletko
 
Robert Resume 8-26-15
Robert Resume 8-26-15Robert Resume 8-26-15
Robert Resume 8-26-15
Robert Thomas
 
LFZH Final Presentation
LFZH Final PresentationLFZH Final Presentation
LFZH Final Presentation
Jillian Sommer
 
Artificial Implants and the Field of Visual Prosthesis Research Paper
Artificial Implants and the Field of Visual Prosthesis Research PaperArtificial Implants and the Field of Visual Prosthesis Research Paper
Artificial Implants and the Field of Visual Prosthesis Research Paper
Brittney Pfeifer
 
Artificial Implants and the Field of Visual Prosthesis
Artificial Implants and the Field of Visual ProsthesisArtificial Implants and the Field of Visual Prosthesis
Artificial Implants and the Field of Visual Prosthesis
Brittney Pfeifer
 
ABJ Biochemistry Manuscript
ABJ Biochemistry ManuscriptABJ Biochemistry Manuscript
ABJ Biochemistry Manuscript
Brittney Pfeifer
 

Viewers also liked (18)

Greenworks Linkedin Portfolio
Greenworks Linkedin PortfolioGreenworks Linkedin Portfolio
Greenworks Linkedin Portfolio
 
how to export a product
how to export a producthow to export a product
how to export a product
 
LFZH Final Report
LFZH Final ReportLFZH Final Report
LFZH Final Report
 
REAM x GE Productive End-Use of MHP 28FEB16
REAM x GE Productive End-Use of MHP 28FEB16REAM x GE Productive End-Use of MHP 28FEB16
REAM x GE Productive End-Use of MHP 28FEB16
 
my last vacation
my last vacation my last vacation
my last vacation
 
Robert Resume 8-26-15
Robert Resume 8-26-15Robert Resume 8-26-15
Robert Resume 8-26-15
 
Bodega marqués de riscal
Bodega marqués de riscalBodega marqués de riscal
Bodega marqués de riscal
 
Acabecadestevejobs 091230131636-phpapp01
Acabecadestevejobs 091230131636-phpapp01Acabecadestevejobs 091230131636-phpapp01
Acabecadestevejobs 091230131636-phpapp01
 
LFZH Final Presentation
LFZH Final PresentationLFZH Final Presentation
LFZH Final Presentation
 
HOW TO EXPORT A PRODUCT
HOW TO EXPORT A PRODUCTHOW TO EXPORT A PRODUCT
HOW TO EXPORT A PRODUCT
 
Red lions futbol
Red lions futbolRed lions futbol
Red lions futbol
 
Visa application thailand
Visa application thailandVisa application thailand
Visa application thailand
 
Muhammad_Aslam_CV
Muhammad_Aslam_CVMuhammad_Aslam_CV
Muhammad_Aslam_CV
 
Artificial Implants and the Field of Visual Prosthesis Research Paper
Artificial Implants and the Field of Visual Prosthesis Research PaperArtificial Implants and the Field of Visual Prosthesis Research Paper
Artificial Implants and the Field of Visual Prosthesis Research Paper
 
Carbon and its structure
Carbon and its structureCarbon and its structure
Carbon and its structure
 
Artificial Implants and the Field of Visual Prosthesis
Artificial Implants and the Field of Visual ProsthesisArtificial Implants and the Field of Visual Prosthesis
Artificial Implants and the Field of Visual Prosthesis
 
ABJ Biochemistry Manuscript
ABJ Biochemistry ManuscriptABJ Biochemistry Manuscript
ABJ Biochemistry Manuscript
 
Models of teaching and learning
Models of teaching  and learningModels of teaching  and learning
Models of teaching and learning
 

Similar to Arduino

How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
footstatus
 
Magnetic door lock using arduino
Magnetic door lock using arduinoMagnetic door lock using arduino
Magnetic door lock using arduino
Sravanthi Sinha
 
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
# peripheral registers  .equ PWR_BASE0x40007000    .equ PWR_CR0x00  .docx# peripheral registers  .equ PWR_BASE0x40007000    .equ PWR_CR0x00  .docx
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
mayank272369
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
ChereCheek752
 
Cs423 raw sockets_bw
Cs423 raw sockets_bwCs423 raw sockets_bw
Cs423 raw sockets_bw
jktjpc
 
The following code is an implementation of the producer consumer pro.pdf
The following code is an implementation of the producer consumer pro.pdfThe following code is an implementation of the producer consumer pro.pdf
The following code is an implementation of the producer consumer pro.pdf
marketing413921
 

Similar to Arduino (20)

How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
 
Sysprog 11
Sysprog 11Sysprog 11
Sysprog 11
 
Magnetic door lock using arduino
Magnetic door lock using arduinoMagnetic door lock using arduino
Magnetic door lock using arduino
 
Sysprog17
Sysprog17Sysprog17
Sysprog17
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷
 
CUDA Deep Dive
CUDA Deep DiveCUDA Deep Dive
CUDA Deep Dive
 
My bitmap
My bitmapMy bitmap
My bitmap
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016
 
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
# peripheral registers  .equ PWR_BASE0x40007000    .equ PWR_CR0x00  .docx# peripheral registers  .equ PWR_BASE0x40007000    .equ PWR_CR0x00  .docx
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
 
Samrt attendance system using fingerprint
Samrt attendance system using fingerprintSamrt attendance system using fingerprint
Samrt attendance system using fingerprint
 
Arduino、Web 到 IoT
Arduino、Web 到 IoTArduino、Web 到 IoT
Arduino、Web 到 IoT
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
 
Arduino and Robotics
Arduino and RoboticsArduino and Robotics
Arduino and Robotics
 
Ieee 1149.1-2013-tutorial-ijtag
Ieee 1149.1-2013-tutorial-ijtagIeee 1149.1-2013-tutorial-ijtag
Ieee 1149.1-2013-tutorial-ijtag
 
Computer networkppt4577
Computer networkppt4577Computer networkppt4577
Computer networkppt4577
 
Npc14
Npc14Npc14
Npc14
 
DEF CON 23 - Phil Polstra - one device to pwn them all
DEF CON 23 - Phil Polstra - one device to pwn them allDEF CON 23 - Phil Polstra - one device to pwn them all
DEF CON 23 - Phil Polstra - one device to pwn them all
 
Cs423 raw sockets_bw
Cs423 raw sockets_bwCs423 raw sockets_bw
Cs423 raw sockets_bw
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
The following code is an implementation of the producer consumer pro.pdf
The following code is an implementation of the producer consumer pro.pdfThe following code is an implementation of the producer consumer pro.pdf
The following code is an implementation of the producer consumer pro.pdf
 

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); }