Hi every one!
I'm having a programming problem..
My project is a fingerprint scanner door security.
when a finger print match the system will unlock the door and send a message to the user.
i also want it to send a message when ID doesn't match..
please help me..
heres my code:
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include <Streaming.h>
#include <Servo.h>
#define __Debug 1 // if debug mode
const int pinServo = 6; // servo pin
const int angleServo = 60; // Rotation angle
#if __Debug
#define DBG(X) Serial.println(X)
#else
#define DBG(X)
#endif
SoftwareSerial mySerial(2, 3); // tx, rx
SoftwareSerial SIM900(7, 8);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
Servo myservo; // create servo object to control a servo
void open_close_door()
{
myservo.attach(pinServo);
for(int i=5; i<angleServo; i++)
{
myservo.write(i);
delay(5);
}
delay(2000);
for(int i=(angleServo-1); i>=5; i--)
{
myservo.write(i);
delay(5);
}
myservo.detach();
}
void setup()
{
SIM900.begin(19200);
SIM900power();
delay(20000); // give time to log on to network.
Serial.begin(9600);
finger.begin(57600);
delay(500);
DBG("setup ok!");
}
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(5000);
}
void sendSMS()
{
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(100);
SIM900.println("AT + CMGS = \"+639988616678\""); // recipient's mobile number, in international format
delay(100);
SIM900.println("Hello, world. This is a text message from an Arduino Uno."); // message to send
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(5000); // give module time to send SMS
SIM900power(); // turn off module
}
void intruderSMS()
{
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(100);
SIM900.println("AT + CMGS = \"+639988616678\""); // recipient's mobile number, in international format
delay(100);
SIM900.println("INTRUDER ALERT!! This is a text message from an Arduino Uno."); // message to send
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(5000); // give module time to send SMS
SIM900power(); // turn off module
}
void loop() // run over and over again
{
if(getFingerprintIDez()>=0)
{
sendSMS();
open_close_door();
DBG("Found match!, open door now!!");
delay(2000);
}
delay(50);
}
// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez()
{
if (!finger.verifyPassword())
{
DBG("Did not find fingerprint sensor :(");
return -1;
}
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;
}
#if __Debug
Serial.print("Found ID #");
Serial.print(finger.fingerID);
Serial.print(" with confidence of ");
DBG(finger.confidence);
#endif
return finger.fingerID;
}