RFID en Bluetooth deurslot (4 / 4 stap)

Stap 4: De Code - (bijgewerkt op 16 April 2016)

 /* * ---------------------------------------------------------------------------- * Typical pin layout used: * ----------------------------------------------------------------------------------------- * MFRC522 Arduino Arduino Arduino Arduino Arduino * Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro * Signal Pin Pin Pin Pin Pin Pin * ----------------------------------------------------------------------------------------- * RST/Reset RST 9 5 D9 RESET/ICSP-5 RST * SPI SS SDA(SS) 10 53 D10 10 10 * SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16 * SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14 * SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15 * */ #include #include #include #include #include #include #define RST_PIN 9 // Configurable, see typical pin layout above #define SS_PIN 10#define Green_LED 6 //pin for green "door unlocked" indicator LED #define Red_LED 7 //pin for red "door locked" indicator LEDString inputString = ""; String command = ""; String value = ""; String password = "startrek"; // this is the password for opening and closing your door // you can set any pasword you like using digit and symbols boolean stringComplete = false; char array1[]="Swipe To Unlock"; // the string to print on the LCD char array2[]=" Door Locked "; char array3[]=" Door Unlocked "; char array4[]=" Locking "; char array5[]=" Unlocking "; char array6[]=" Accepted "; char array7[]=" Swipe To Lock "; int tim = 1; //the value of delay time// initialize the library with the numbers of the interface pins LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. Servo myservo;String read_rfid; // nfc tags ID String ok_rfid_1="94e68de2"; String ok_rfid_2="f5642a50"; String ok_rfid_3="43ef222993c81";int addr = 1; // initalise eeprom address int eVal = 0; // initalise value to be stored in eeprom int lockPosition; // initialise lockPosition, used to value to sore in eVal int servo_position; int BUTTON1 = 8; // initialise the pin input of the lock/unlock buttonvoid setup() { Serial.begin(9600); // Initialize serial communications with the PC while (!Serial); SPI.begin(); mfrc522.PCD_Init(); inputString.reserve(50); // reserve 50 bytes in memory to save for string manipulation command.reserve(50); value.reserve(50); boolean stringOK = false; { lcd.init(); //initialize the lcd lcd.backlight(); //open the backlight lcd.begin(16,2); } // sets pin modes input/output and lights led pinMode(Green_LED, OUTPUT); pinMode(Red_LED, OUTPUT); digitalWrite(Green_LED, LOW); digitalWrite(Red_LED, HIGH); pinMode(BUTTON1,INPUT); myservo.attach(5); // servo pin number // sets initial locl position lockPosition = EEPROM.read(1); // Serial.print(EEPROM.read(1)); if(lockPosition == 1){ digitalWrite(Red_LED, LOW); digitalWrite(Green_LED, HIGH); } else { digitalWrite(Red_LED, HIGH); digitalWrite(Green_LED, LOW); lockUnlock(); } swipeText();}/* * Dump a byte array as hex values to Serial. */ void dump_byte_array(byte *buffer, byte bufferSize) { read_rfid=""; for (byte i = 0; i < bufferSize; i++) { read_rfid=read_rfid + String(buffer[i], HEX); } }void lockUnlock() { // locks or unlocks door myservo.attach(5); if(lockPosition == 1) { lock1(); servo_position = 0; myservo.write(servo_position); digitalWrite(Red_LED, HIGH); digitalWrite(Green_LED, LOW); delay(2500); lockPosition = 2; eVal = lockPosition; EEPROM.write(1,eVal); // Serial.print(eVal); } else if(lockPosition == 2) { lock2(); servo_position = 180; myservo.write(servo_position); digitalWrite(Red_LED, LOW); digitalWrite(Green_LED, HIGH); delay(2500); lockPosition = 1; eVal = lockPosition; EEPROM.write(1,eVal); // Serial.print(eVal); } myservo.detach(); }void swipeText() // sends text to the lcd screen { if(lockPosition == 1){ lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner. lcd.setCursor(0,0); // set the cursor to column 15, line 0 for (int positionCounter1 = 0; positionCounter1 < 15; positionCounter1++) { lcd.print(array3[positionCounter1]); // Print a message to the LCD. delay(tim); //wait for 250 microseconds } lcd.setCursor(0,1); // set the cursor to column 15, line 1 for (int positionCounter = 0; positionCounter < 15; positionCounter++) { lcd.print(array7[positionCounter]); // Print a message to the LCD. delay(tim); //wait for 250 microseconds } } else if(lockPosition == 2){ lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner. lcd.setCursor(0,0); // set the cursor to column 15, line 0 for (int positionCounter1 = 0; positionCounter1 < 15; positionCounter1++) { lcd.print(array2[positionCounter1]); // Print a message to the LCD. delay(tim); //wait for 250 microseconds } lcd.setCursor(0,1); // set the cursor to column 15, line 1 for (int positionCounter = 0; positionCounter < 15; positionCounter++) { lcd.print(array1[positionCounter]); // Print a message to the LCD. delay(tim); //wait for 250 microseconds } } }void lock1() // sends text to the lcd screen locking { lcd.clear(); lcd.setCursor(0,0); for (int positionCounter1 = 0; positionCounter1 < 15; positionCounter1++) { lcd.print(array6[positionCounter1]); delay(tim); } lcd.setCursor(0,1); for (int positionCounter1 = 0; positionCounter1 < 10; positionCounter1++) { lcd.print(array4[positionCounter1]); delay(tim); } }void lock2() // sends text to the lcd screen for unlocking { lcd.clear(); lcd.setCursor(0,0); for (int positionCounter1 = 0; positionCounter1 < 15; positionCounter1++) { lcd.print(array6[positionCounter1]); delay(tim); } lcd.setCursor(0,1); for (int positionCounter1 = 0; positionCounter1 < 12; positionCounter1++) { lcd.print(array5[positionCounter1]); delay(tim); } }void loop() { // checks for lock/unlock button press if(digitalRead(BUTTON1) == HIGH){ lockUnlock(); swipeText(); } // checks if bluetooth has sent a command // if arduino receive a string termination character like \n stringComplete will set to true if (stringComplete) { //Serial.println(inputString); delay(100); // identified the posiion of '=' in string and set its index to pos variable int pos = inputString.indexOf('='); // value of pos variable > or = 0 means '=' present in received string. if (pos > -1) { // substring(start, stop) function cut a specific portion of string from start to stop // here command will be the portion of received string till '=' // let received string is open=test123 // then command is 'open' command = inputString.substring(0, pos); // value will be from after = to newline command // for the above example value is test123 // we just ignoreing the '=' taking first parameter of substring as 'pos+1' // we are using '=' as a separator between command and vale // without '=' any other character can be used // we are using = menas our command or password must not contains any '=', otherwise it will cause error value = inputString.substring(pos+1, inputString.length()-1); // extract command up to \n exluded //Serial.println(command); //Serial.println(value); // checks password from bluetooth and is correct locks or unlocks the door // password.compareTo(value) compare between password tring and value string, if match return 0 if(!password.compareTo(value) && (command == "OPEN")){ // if password matched and command is 'OPEN' than door should open lockUnlock(); // call lockUnlock() function Serial.println(" OPEN"); // sent open feedback to phone delay(100); swipeText(); } if(!password.compareTo(value) && (command == "CLOSE")){ // if password matched and command is 'CLOSE' than door should close lockUnlock(); Serial.println(" CLOSE"); // sent " CLOSE" string to the phone delay(100); swipeText(); } if(password.compareTo(value)){ // if password not matched than sent wrong feedback to phone Serial.println(" WRONG"); delay(100); swipeText(); } } // clear the string for next iteration inputString = ""; stringComplete = false; } // looks for rfid tag to be presented if ( ! mfrc522.PICC_IsNewCardPresent()) return; // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) return; dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size); // checks if an rfid tags ID matches the stored list, if so it will then lock or unlock the door Serial.println(read_rfid); if (read_rfid==ok_rfid_1) { //ok, open the door. lockUnlock(); swipeText(); } //Add below as many "keys" as you want if (read_rfid==ok_rfid_2) { //also ok, open the door lockUnlock(); swipeText(); } //Add below as many "keys" as you want if (read_rfid==ok_rfid_3) { //also ok, open the door lockUnlock(); swipeText(); } }void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); //Serial.write(inChar); // add it to the inputString: inputString += inChar; // if the incoming character is a newline or a carriage return, set a flag // so the main loop can do something about it: if (inChar == '\n' || inChar == '\r') { stringComplete = true; } } } 

Gerelateerde Artikelen

Eenvoudige Bluetooth Enabled deur vergrendeling met Arduino + Android

Eenvoudige Bluetooth Enabled deur vergrendeling met Arduino + Android

dank aan iedereen die dit project ondersteund en gestemd voor het in de Arduino Challenge! Ik kreeg de tweede prijs en hoop in de nabije toekomst meer Arduino wedstrijden deelnemen.Dit leerprogramma zal verklaren een eenvoudige manier om een wachtwoo
RFID Auto Lock/Unlock v1.0

RFID Auto Lock/Unlock v1.0

In deze video zie je me ontgrendelen van de auto met behulp van een RFID-tag, wacht 25sec en de auto-relocks.Basic overzichtDit project schetst een manier om te vergrendelen en ontgrendelen van uw auto met behulp van radiofrequentie identificatie (RF
RFID deurslot met Arduino

RFID deurslot met Arduino

Hier zijn we met de klassieke RFID-deurslot. It's klassieker in die hele, "We leven in de toekomst en het als iets vanzelfsprekends op dit punt" zin. In deze tutorial zullen we een deur klink die kan worden geopend met swipe van een RFID-Tag opg
Arduino & Android gebaseerd Bluetooth controle wachtwoord beschermd slim deurslot (behalve thuis)

Arduino & Android gebaseerd Bluetooth controle wachtwoord beschermd slim deurslot (behalve thuis)

Wij iedereen zijn bezorgd over de veiligheid van ons huis. Wereld steeds slimmer en slimmer elke dag en we willen controle en ons ding in slimmere manier beveiligd. In deze tutorial die ik hoe uitleggen zal gemaakt gebaseerd een arduino DIY smart loc
Arduino RFID deurslot

Arduino RFID deurslot

*** bijgewerkt 8/9/2010 ***Ik wilde een gemakkelijke en veilige manier om te gaan van mijn garage. RFID was de beste manier om te ontgrendelen mijn deur, zelfs met mijn handen vol open ik de deur en de druk op het open! Ik bouwde een eenvoudige schak
Weer bewijs, Bluetooth staat RFID lezer

Weer bewijs, Bluetooth staat RFID lezer

dit instructable verbonden van de populaire BlueSmirf Bluetooth-module met de ID12 RFID lezer en toont hoe te maken van een stof- en waterbestendig (IP55) RFID-lezer die id's worden verzonden naar uw PC of mobiele telefoon via Bluetooth radio zonder
DIY RFID deurslot

DIY RFID deurslot

Instructies voor het bouwen van uw eigen doen jezelf RFID deur vergrendeling voor uw huis, garage, enz.Ook, hebt u een 3D-printer kunt u ook gebruiken mijn case ontwerpen of wijzigen van mijn ontwerpen om je eigen te maken. Ze zijn niet helemaal perf
Scure Lock met RFID-Tag en PIN

Scure Lock met RFID-Tag en PIN

U gecontroleerd in een hotel en gezien een RFID-tag voor toegang tot uw kamer. Als u uw kaart verloren en iemand anders had kunt de verloren kaart toegang tot uw kamer. Zou het niet veiliger zijn als een ander stuk van informatie zoals PIN is vereist
Arduino RC522 RFID deur ontgrendelen

Arduino RC522 RFID deur ontgrendelen

Hallo is allemaal hier mijn demo.Want ik heb mijn RFID-lezer, ik wilde alleen maar het maken van een RFID-deur systeem voor mijn appartement de deur ontgrendelen. Aanvankelijk, ik heb de workflow boven, ontworpen als een Newbie, zijn niet vrij een ee
Deuropener van de Garage van de Arduino RFID

Deuropener van de Garage van de Arduino RFID

In dit project, zullen we gebruiken de kracht van RFID te boren in uw garagedeur openingssysteem. We gaan naar brug een verbinding in de opener schakelen via een RobotGeek relais boord, starten de deur openen als u de knop had gedrukt. Deze code zal
Android / Arduino - BLUETOOTH deur vergrendeling TOEGANGSBEHEER voor elektrische Strike Lock

Android / Arduino - BLUETOOTH deur vergrendeling TOEGANGSBEHEER voor elektrische Strike Lock

Hello wereld! Vandaag maakte ik een APP te Lock & Unlock een elektrische deurslot met behulp van een relais, beschermd door een wachtwoord. De app is beschikbare open source! Gewoon contact met me op! contact Volg de volgende stap het schema, Code, o
Secret Knock opsporen deurslot

Secret Knock opsporen deurslot

uw geheime schuilplaats te beschermen tegen indringers met een vergrendeling die wordt alleen geopend wanneer het hoort de geheime knock.Dit begon als een beetje een grap-project, maar bleek te zijn verrassend nauwkeurig op te stoten oordelen. Als de
Arduino RFID-RC522 - deur toegangscontrole / RFID deur VERGRENDELEN

Arduino RFID-RC522 - deur toegangscontrole / RFID deur VERGRENDELEN

Hallo mensen! Vandaag maakte ik een RFID-deurslot. De lamp fungeert als een elektrische deurslot omdat ik niet een elektrische vergrendeling, u gewoon het deurslot toevoegen aan de estafette in plaats van de lamp. Check de link voor de schematische c
Arduino RFID Lock vak

Arduino RFID Lock vak

Hallo, zal vandaag ik je laten zien hoe maak je een RFID Lock box.Stap 1: voorbereidingJe moet1 x houten doos - http://www.amazon.com/Darice-9151-58-Rectangle-Woo...1 x Parallax alleen-lezen RFID scanner - http://www.parallax.com/product/281401 x Ard