Amirrezaaaaaa
Published © TAPR-OHL

RFID Two-Card Door Lock and Bluetooth Control

RFID two-card door lock and Bluetooth control.

BeginnerShowcase (no instructions)2,727
RFID Two-Card Door Lock and Bluetooth Control

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
RFID reader (generic)
×1
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×1
DC motor (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

untitled_sketch_bb_OsHjUqtLfU.png

Code

Rfid_door_lock_and_bluetooth_control_kh_.ino

Arduino
 /* -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno/101       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 "SPI.h"
#include "MFRC522.h"
#define SS_PIN 53
#define RST_PIN 5
int motorl = 42;
int motorr = 43;
String command;
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;
void setup() {
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();
  mySerial.begin(9600);
  mySerial.println("RFID door lock and bluetooth control");//
}
void motoropened() {
  digitalWrite(motorl, HIGH);
}
void motorclosed() {
  digitalWrite(motorr, HIGH);
}
void motorStop() {
  digitalWrite(motorr, LOW);
  digitalWrite(motorl, LOW);
}
void dooropened() {
  motoropened();
  delay(1000);
  motorStop();
  delay(5000);
  motorclosed();
  delay(800);
  motorStop();
}
void loop() {
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
    return;
  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
  if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
      piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
      piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
    Serial.println(F("Your tag is not of type MIFARE Classic."));
    return;
  }
  String strID = "";
  for (byte i = 0; i < 4; i++) {
    strID +=
      (rfid.uid.uidByte[i] < 0x10 ? "0" : "") +
      String(rfid.uid.uidByte[i], HEX) +
      (i != 5 ? ":" : "");
  }
  strID.toUpperCase();
  Serial.print("Tap card key: ");
  Serial.println(strID);
  delay(1000);
  //*****************************************************************************
  if (strID.indexOf("56:68:7F:8D") >= 0) {
    mySerial.println("amirreza");//
    dooropened();
    return;
  }
  //*****************************************************************************
  if (strID.indexOf("B0:23:F2:79") >= 0) {
    mySerial.println("mohammadi");
    dooropened();
    return;
  }
  //*****************************************************************************

  else {

    return;
  }

}

Credits

Amirrezaaaaaa

Amirrezaaaaaa

0 projects • 0 followers

Comments