Things used in this project

Hardware components:
A000066 iso both
Arduino UNO & Genuino UNO
This is the base chipset I used to make this project.
×1
Rfid
RFID Module for Tessel
MFRC522 / RFID-RC522 chipset. https://playground.arduino.cc/Learning/MFRC522
×1
1586 00
Adafruit NeoPixel Ring: WS2812 5050 RGB LED
Ring with 24 pixels, see: https://www.adafruit.com/product/1586
×1
12002 04
Breadboard (generic)
×1
11026 02
Jumper wires (generic)
Connected them between breadboard and components. See Schematics further down.
×11
Adafruit industries ada62 image 75px
USB-A to B Cable
To power and upload code to Arduino UNO
×1
Software apps and online services:
Ide web
Arduino IDE
I programmed and connected using the IDE software.
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)
I had to solder the RFID-RC522 to make sure it had 100 % connection.

Schematics

Image Schematics
A plain PNG picture of the connections
Colorrfidscan bb vxysvewgkh
Fritzing Schematics
Open in Fritzing (http://fritzing.org/download/) to see schematics in several views.
colorrfidscan_d4yGH7Hmqf.fzz

Code

Arduino Uno CodeArduino
The complete code
#include <Adafruit_NeoPixel.h>
#include <require_cpp11.h>
#include <deprecated.h>
#include <MFRC522.h>
#include <MFRC522Hack.h>
#include <MFRC522Extended.h>
#include <MFRC522Debug.h>
#include "SPI.h"

// Setup of configurations
const int      delayval  =  50; // Time each pixel pauses to do it's duty.
const int      PIN       =  6; // Data output to Adafruit NeoPixel
const int      NUMPIXELS =  24; // Number of pixels in the ring ^
const int      SS_PIN    =  10; // Data PIN for MFRC522
const int      RST_PIN   =  9; // Reset PIN for MFRC522
const int      TIME      =  150; // Time between each NeoPixel blink.

// Defining needed variables for the NeoPixel: pixels
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

// Defining colors
const uint32_t red       =  pixels.Color(255, 0, 0);
const uint32_t green     =  pixels.Color(0, 255, 0);
const uint32_t yellow    =  pixels.Color(255, 255, 0);
const uint32_t blank     =  pixels.Color(0, 0, 0);

MFRC522 rfid(SS_PIN, RST_PIN); // Prepares PINS
MFRC522::MIFARE_Key key;

/**
 * Function setup:
 * Desc:  Main function for Arduino programming language.
 * Extra: It runs only once during startup of the script.
 */
void setup() {
  Serial.begin(9600);
  Serial.println("Starting all...\n\n");
  pixels.begin();
  pixels.setBrightness(20); // This is to make sure the lights won't burn up.
  SPI.begin(); // Make the NeoPixel and microcontroller communicate
  rfid.PCD_Init(); 
}

/**
 * Function loop:
 * Desc:  Runs over and over, hence loop.
 */
void loop() {
  setAll(yellow); // Sets initial color of the NeoPixel ring to yellow.
  
  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 != 3 ? ":" : "");
  }
  strID.toUpperCase();
  
  if (validateCard(strID)) {
    Serial.println("*** Access granted! ***");
    Serial.print("*** The source was just accessed by a card with this ID: ");
    Serial.println(strID);
    Serial.print("");
    for(int i=0;i<10;i++){ // Repeat ten times, total of 1.5 seconds excluding light time change.
      setAll(green);
      delay(TIME);
      setAll(blank);
      delay(TIME);
    }
    return;
  }
  else {
    Serial.println("*** Access denied! ***");
    Serial.print("*** You tried a card with this id: ");
    Serial.println(strID);
    Serial.println("");
    for(int i=0;i<4;i++){ // Repeat only four times to avoid using too much time, total of 600ms.
      setAll(red);
      delay(TIME);
      setAll(blank);
      delay(TIME);
    }
    return;
  }
}

/**
 * Function setAll:
 * Desc: Sets all pixels as defined in
 * configuration
 */
void setAll(uint32_t color) {
  for(int i=0;i<NUMPIXELS;i++){
    pixels.setPixelColor(i, color);
    pixels.show();
  }
}

/**
 * Function validateCard:
 * Desc: Checks ID of card and returns if the
 * right card was scanned.
 */
bool validateCard(String usercard) {
  // Insert your own card ID's here, insert more with else if under
  if(usercard.indexOf("AA:BB:CC:DD") >= 0) {
    return true;
  }
  else if(usercard.indexOf("AA:BB:CC:DD") >= 0) {
    return true;
  }
  else return false;
}

Credits

Werzaire
Werzaire
1 project • 0 followers
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login