Shubham Shinganapure
Published © CC BY-NC-SA

An Alternate RFID Key for Bike Security

For bike security, There is only ignition lock switch. And it can be easily hacked by the thief. Here I come with a DIY solution for that.

IntermediateFull instructions provided1.5 hours4,287
An Alternate RFID Key for Bike Security

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
rfid reader
×1
12v relay
×1
bc547 transitor
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Linear Regulator (7805)
Linear Regulator (7805)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Hot glue gun (generic)
Hot glue gun (generic)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Schematics

Alternate RFID Key

Code

Alternet rfid key

Arduino
This is the Main code. but you need one more code, follow the code from the download link
/*
program by Shubham Shinganapure on 29-08-2019

for RFID Key For bike 
*/

#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_1_PIN        10         // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
#define SS_2_PIN        8          // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1

#define NR_OF_READERS   2

byte ssPins[] = {SS_1_PIN, SS_2_PIN};

MFRC522 mfrc522[NR_OF_READERS];   // Create MFRC522 instance.
int ledRed = A1;
int rly = 6;

const int ledBlue =  A5;
int ledState = LOW;   

unsigned long previousMillis = 0;  
const long interval = 2000; 
const long interval2 = 70; 
int flg=0;


void setup() {
  pinMode(ledRed,OUTPUT);
  pinMode(ledBlue,OUTPUT);
  pinMode(rly,OUTPUT);
  SPI.begin();        // Init SPI bus
digitalWrite(rly,LOW);
digitalWrite(ledBlue,HIGH);
  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
    //Serial.print(F("Reader "));
   // Serial.print(reader);
    //Serial.print(F(": "));
    mfrc522[reader].PCD_DumpVersionToSerial();
  }
//delay(5000);
}

/**
 * Main loop.
 */
 int i =0 ;
 char arry2[5] = {0x06,0xF8,0x51,0x1B,0}; // put your cards ID here. for example my card ID is 06,F8,51,1B so write it by this way{0x06,0xF8,0x51,0x1B,0} 
  char arry[5] = {0};
  


void loop() {
   //Blink();
   readTag();
              if(strncmp(arry2,arry,4) == 0)
                 { 
                 
                  digitalWrite(rly,HIGH);
                 // digitalWrite(ledBlue,HIGH);
                  Blink();
                 
                  //arry[5] = {0};
                 // memset(arry,0,5);
                
                 }
            if( flg==1 &&(strncmp(arry2,arry,4) != 0)) 
            {
              digitalWrite(rly,LOW);
               //digitalWrite(ledBlue,LOW);
              Blink2(); 
               memset(arry,0,5);
               flg=0;
                }
}

void readTag()
{
  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    // Look for new cards

    if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
     // Serial.print(F("Reader "));
     // Serial.print(reader);
      // Show some details of the PICC (that is: the tag/card)
      //Serial.print(F(": Card UID:"));
      dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
      //Serial.println();
      for(i = 0;i < 4;i++)
      {
       //Serial.print(mfrc522[reader].uid.uidByte[i],HEX);
       arry[i] =  mfrc522[reader].uid.uidByte[i];
      flg=1;
       //Serial.println(arry[i],HEX);
      } 

      for(i = 0;i < 4;i++)
             //Serial.print(arry[i],HEX);

              // Serial.println();

      //Serial.print(F("PICC type: "));
      MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
      //Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));

      // Halt PICC
      mfrc522[reader].PICC_HaltA();
      // Stop encryption on PCD
      mfrc522[reader].PCD_StopCrypto1();
    } //if (mfrc522[reader].PICC_IsNewC
  } //for(uint8_t reader
} 

/**
 * Helper routine to dump a byte array as hex values to Serial.
 */
void dump_byte_array(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    //Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    //Serial.print(buffer[i], HEX);
  }
}

void Blink() {
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }
    digitalWrite(ledBlue, ledState);
  }
}
void Blink2() {
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval2) {
    previousMillis = currentMillis;
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }
    digitalWrite(ledBlue, ledState);
  }
}

Credits

Shubham Shinganapure

Shubham Shinganapure

16 projects • 60 followers
I am an Electronics Engineer and hobbyist. Love to work with Machines.

Comments