Rfid Coding Project

hello,

i have a small project that needs to be done and i thought it was simple. however, i try to combine a coding together but isn't work. my input was the RFID and infrared sensor, the rfid will scan the card and will put down a gate and somehow the infrared sensor will be the indicator and also be the input to bring the gate up. maybe to do something wrong on my coding, can someone help me understanding on what should i do. please.....

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

 int IR = 2;        //infrared sensor 
 int servoPin = 3;
 Servo Servol;
 int RL = 5;        //red led
 int GL = 4;        //green led
 
void setup() 
{
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  Serial.println("Approximate your card to the reader...");
  Serial.println();
  Servol.attach(servoPin);

  pinMode(0, OUTPUT);   // Red LED
  pinMode(1, OUTPUT);   // Green LED
  pinMode(IR,INPUT);    // infrared sensor
 
}
void loop() 
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "70 4F 5D A8") //change here the UID of the card
  {
    Serial.println("Authorized access");
    Serial.println();
    delay(500);
    Servol.write(180); //Gate Down
    delay(500);

      if (digitalRead(IR == LOW))   
    {
      digitalWrite(RL, HIGH);  // Red LED
      digitalWrite(GL, LOW);   // Green LED
      delay (500);
    }

      else if (digitalRead(IR == HIGH))
    {
      delay (500);
      Servol.write(0);
      delay (500);
      digitalWrite(RL, LOW);  // Red LED
      digitalWrite(GL, HIGH);   // Green LED
      Serial.println("Gate Up");
      delay (500);
    }

  else 
  {
    Serial.println(" Access denied");
    delay(500);
  }
  }
}
  1. sketch #1 to make sure you are reading RFID correctly by printing to Serial Monitor
  2. sketch #2 to be able to control infrared sensor
  3. combine sketch #1 and sketch #2

So, we know what you want the code to do. What does it ACTUALLY do?

You need to sh*tcan that stupid example that you started with. That code assumes that the RFID is the center of the universe. It is NOT.