Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <HTTPClient.h>
- #include <Adafruit_Fingerprint.h>
- #define greenLEDpin 21
- #define redLEDpin 19
- #define buzzerPin 18
- #define RXD2 16
- #define TXD2 17
- #define mySerial Serial2
- Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- const char * ssid = "network6";
- const char * password = "123456789";
- String GOOGLE_SCRIPT_ID = "------mKRkBEuUqM-f3K7aYwZFHVy8osDsOB8MDdOSNWbfgLQLsaXF4AXGh_rfkO1kEnO1";
- String userName [3] = {"1Safwan%20First",
- "2Mhmad%20Second",
- "%D9%85%D8%AD%D9%85%D8%AF%20%D8%B1%D8%AC%D8%A8",
- };
- String userIDNumber [3] = {"11223344",
- "21223344",
- "32334455"
- };
- int userState [3] = {0,
- 0,
- 0
- };
- String SteteToSend[2] = {"Signed%20OUT", "Signed%20IN"};
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- void setup() {
- Serial.begin(9600);
- pinMode(greenLEDpin, OUTPUT);
- pinMode(redLEDpin, OUTPUT);
- pinMode(buzzerPin, OUTPUT);
- digitalWrite(greenLEDpin, LOW);
- digitalWrite(redLEDpin, LOW);
- digitalWrite(buzzerPin, LOW);
- controlOutputs(1, 0, 0, 100);
- controlOutputs(0, 1, 0, 100);
- controlOutputs(0, 0, 1, 100);
- controlOutputs(0, 1, 0, 100);
- initFingerPrint();
- WiFi_Setup();
- }//end of Setup
- void loop() {
- getFingerprintID();
- }//end of LOOP
- void WiFi_Setup() {
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- Serial.print("Connecting to Wi-Fi");
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("OK");
- }
- void Send_Data_To_Google_Sheets(String AA, String BB, String CC) {
- String param;
- param = "dataA=" + AA;
- param += "&dataB=" + BB;
- param += "&dataC=" + CC;
- write_to_google_sheet(param);
- }
- void write_to_google_sheet(String params) {
- HTTPClient http;
- String url = "https://script.google.com/macros/s/" + GOOGLE_SCRIPT_ID + "/exec?" + params;
- //Serial.print(url);
- Serial.println("Posting Data to Google Sheets");
- //---------------------------------------------------------------------
- //starts posting data to google sheet
- http.begin(url.c_str());
- http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
- int httpCode = http.GET();
- Serial.print("HTTP Status Code: ");
- Serial.println(httpCode);
- //---------------------------------------------------------------------
- //getting response from google sheet
- String payload;
- if (httpCode > 0) {
- payload = http.getString();
- Serial.println("Payload: " + payload);
- }
- //---------------------------------------------------------------------
- http.end();
- }
- void initFingerPrint() {
- Serial2.begin(57600, SERIAL_8N1, RXD2, TXD2);
- while (!Serial);
- delay(100);
- Serial.println("\n\nAdafruit finger detect test");
- delay(5);
- if (finger.verifyPassword()) {
- Serial.println("Found fingerprint sensor!");
- } else {
- Serial.println("Did not find fingerprint sensor :(");
- while (1) {
- delay(1);
- }
- }
- Serial.println(F("Reading sensor parameters"));
- finger.getParameters();
- Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX);
- Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
- Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
- Serial.print(F("Security level: ")); Serial.println(finger.security_level);
- Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX);
- Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
- Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);
- finger.getTemplateCount();
- if (finger.templateCount == 0) {
- Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
- }
- else {
- Serial.println("Waiting for valid finger...");
- Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
- }
- }
- uint8_t getFingerprintID() {
- uint8_t p = finger.getImage();
- switch (p) {
- case FINGERPRINT_OK:
- Serial.println("Image taken");
- controlOutputs(0, 1, 1, 250);
- break;
- case FINGERPRINT_NOFINGER:
- Serial.println("No finger detected");
- return p;
- case FINGERPRINT_PACKETRECIEVEERR:
- Serial.println("Communication error");
- return p;
- case FINGERPRINT_IMAGEFAIL:
- Serial.println("Imaging error");
- return p;
- default:
- Serial.println("Unknown error");
- return p;
- }
- // OK success!
- p = finger.image2Tz();
- switch (p) {
- case FINGERPRINT_OK:
- Serial.println("Image converted");
- break;
- case FINGERPRINT_IMAGEMESS:
- Serial.println("Image too messy");
- return p;
- case FINGERPRINT_PACKETRECIEVEERR:
- Serial.println("Communication error");
- return p;
- case FINGERPRINT_FEATUREFAIL:
- Serial.println("Could not find fingerprint features");
- return p;
- case FINGERPRINT_INVALIDIMAGE:
- Serial.println("Could not find fingerprint features");
- return p;
- default:
- Serial.println("Unknown error");
- return p;
- }
- // OK converted!
- p = finger.fingerSearch();
- if (p == FINGERPRINT_OK) {
- Serial.println("Found a print match!");
- } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
- Serial.println("Communication error");
- return p;
- } else if (p == FINGERPRINT_NOTFOUND) {
- //Serial.println("Did not find a match");
- for (int i = 0; i < 3; i++) {
- controlOutputs(0, 1, 1, 250);
- controlOutputs(0, 0, 0, 50);
- }
- controlOutputs(0, 1, 0, 50);
- return p;
- } else {
- Serial.println("Unknown error");
- return p;
- }
- if ((finger.fingerID) != -1) {
- controlOutputs(1, 0, 1, 250);
- controlOutputs(1, 0, 0, 50);
- /////////////////////////////////////////////////
- if (userState[(finger.fingerID - 1)] == 0) {
- userState[(finger.fingerID - 1)] = 1;
- }
- else {
- userState[(finger.fingerID - 1)] = 0;
- }
- Send_Data_To_Google_Sheets(userName[(finger.fingerID - 1)], userIDNumber[(finger.fingerID - 1)], SteteToSend[userState[(finger.fingerID - 1)]]);
- delay(500);
- controlOutputs(0, 1, 0, 50);
- }
- /////////////////////////////////////////////////
- // found a match!
- Serial.print("Found ID #"); Serial.print(finger.fingerID);
- Serial.print(" with confidence of "); Serial.println(finger.confidence);
- return finger.fingerID;
- }
- void controlOutputs(int green, int red, int buzzer, int delayTime) {
- digitalWrite(greenLEDpin, green);
- digitalWrite(redLEDpin, red);
- digitalWrite(buzzerPin, buzzer);
- delay(delayTime);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement