top of page
Editing Components.png

In the final task we were asked to build and program a machine that uses at least one input and one output the Arduino system.
I chose to code an RFID circuit so that it detects if the cards it reads are in the system, it will authorize access to the entrance.

When the entry is approved, a small melody sounds, the LCD screen shows: Entry Approved, a green light is on and the motor (of the door) opens for 3 seconds.
When it does not recognize the card, access is denied, 3 error beeps are heard and the red light comes on.

//set libraries and pins

#include <SPI.h>

#include <RFID.h>

#include <LiquidCrystal_I2C.h>

#include <Servo.h>

#define SS_PIN 10

#define RST_PIN 9

RFID rfid(SS_PIN, RST_PIN);

const int buzzer = 3; //set buzzer to pin 3

const int green_LED = 4; //set green LED to pin 4

const int red_LED = 5; //set red LED to pin 5

 

Servo dorServo; //named Servo motor

LiquidCrystal_I2C lcd(0x27, 16, 2);

String rfidCard;

 

void setup() {

  Serial.begin(9600);

  Serial.println("Starting the RFID Reader...");

  SPI.begin();

  rfid.init();

  lcd.init();

  lcd.backlight();

  dorServo.attach(6);

  //pinMode(buzzer, OUTPUT);

  pinMode(green_LED, OUTPUT);

  pinMode(red_LED, OUTPUT);

}

 

void loop() {

  lcd.clear(); //clear LCD screen after acting

 

  if (rfid.isCard()) {

    while (rfid.readCardSerial()) {

      rfidCard = String(rfid.serNum[0]) + " " + String(rfid.serNum[1]) + " " + String(rfid.serNum[2]) + " " + String(rfid.serNum[3]);

      Serial.println(rfidCard);

      if (rfidCard == "101 5 168 172" || rfidCard == "189 15 11 50") {

        lcd.setCursor(0,0); //start writing on LCD screen on first pixel

        lcd.print("Entry approved!");

        delay(10);

        dorServo.write(180); //Servo motor open to 180 degrees

        digitalWrite(green_LED, HIGH); //green LED turn on

        //approval sounds:

        tone(buzzer, 3950);

        delay(150);

        tone(buzzer, 3800);

        delay(150);

        tone(buzzer, 3550);

        delay(150);

        tone(buzzer, 4150);

        delay(200);

        tone(buzzer, 4250);

        delay(250);

        noTone(buzzer); //stop buzzer sounds

        delay(3000);

        dorServo.write(0); //servo motor stop acting

        digitalWrite(green_LED, LOW); //green LED turn off

      } else {

        lcd.setCursor(0,0);

        lcd.print("Access denied"); //appeare on the LCD screen first row

        lcd.setCursor(0,1);

        lcd.print("X X X X X X X X"); //appeare on the LCD screen second row

        delay(10);

        digitalWrite(red_LED, HIGH); //red LED turn on

        tone(buzzer, 4000); //buzzer sound on

        delay(150);

        digitalWrite(red_LED, LOW); //red LED turn off

        noTone(buzzer); //buzzer sound stop

        delay(150);

        digitalWrite(red_LED, HIGH); //red LED turn on

        tone(buzzer, 4000); //buzzer sound on

        delay(150);

        digitalWrite(red_LED, LOW); //red LED turn off

        noTone(buzzer); //buzzer sound stop

        delay(150);

        digitalWrite(red_LED, HIGH); //red LED turn on

        tone(buzzer, 4000); //buzzer sound on

        delay(150);

        digitalWrite(red_LED, LOW); //red LED turn off

        noTone(buzzer); //buzzer sound stop

        delay(3000);

      }

    }

    rfid.halt();

    rfidCard==0; //reset rfidCard value to 0

  }

}

RFID circuit coding for entry confirmation
IMG_2187.JPG
IMG_2189.JPG
IMG_2184.JPG
bottom of page