#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Servo.h>
#define RST_PIN 5 // Configurable, see typical pin layout above
#define SS_PIN 53 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
LiquidCrystal_I2C lcd(0x27,16,2);
String uid1 = "53 2C 91 0D";
String uid2 = "32 D7 46 1E";
****************************************************************************
int IR1 = 2;
int IR2 = 4;
int slot = 6;
int flag1 = 0;
int flag2 = 0;
int A = 0
****************************************************************************
/*Servo servo_A2;
long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}*/
void setup()
{
*************************************************************************
pinMode (IR1, INPUT);
pinMode (IR2, INPUT);
***********************************************************************
/*servo_A2.attach(A2, 500, 2500);
lcd.init();
lcd.init();
lcd.backlight();
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(); */
}
void loop()
{
***************************************************************************
if ( digitalRead (IR1) == LOW && flag1 == 0 )
{
if (slot > 0)
{
flag1 = 1;
if (flag2 == 0)
{
if (content.substring(1) == uid1 && A = 0)
{
A = A+1;
slot = slot-1;
lcd.setCursor(0,0);
lcd.setCursor(0,1);
lcd.print("Hello Mr.Ahmed");
servo_A2.write(0);
delay(3000);
}
}
else
{
lcd.setCursor(0,0);
lcd.print("Sorry");
lcd.setCursor(0,1);
lcd.print("Parking Full");
delay(3000);
lcd.clear();
}
}
}
if ( digitalRead (IR2) == LOW && flag2 == 0)
{
flag2 = 1;
if ( flag1 == 0 )
{
slot = slot+1;
if (content.substring(1) == uid1 && A = 1)
{
lcd.setCursor(0,0);
lcd.setCursor(0,1);
lcd.print("Goodbye Mr.Ahmed");
servo_A2.write(0);
delay(3000);
A = 0;
}
}
}
if ( flag1 == 1 && flag2 == 1 )
{
delay(2000);
flag1 = 0 , flag2 = 0;
servo_A2.write(90);
}
***************************************************************************
/*servo_A2.write(90);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Scan Tag ");
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
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));
}
lcd.clear();
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
*************************************************************************************************************************
if (content.substring(1) == uid1) //change here the UID of the card/cards that you want to give access
{
Serial.println("Authorized access");
Serial.println();
lcd.setCursor(0,0);
lcd.print("Tag 01");
lcd.setCursor(0,1);
lcd.print("Hello Mr.Ahmed");
delay(3000);
}
else if (content.substring(1) == uid2) //change here the UID of the card/cards that you want to give access
{
Serial.println("Authorized access");
Serial.println();
lcd.setCursor(0,0);
lcd.print("Tag 02");
lcd.setCursor(0,1);
lcd.print("Authorized access");
delay(3000);
}
else if (content.substring(1) == uid3) //change here the UID of the card/cards that you want to give access
{
Serial.println("Authorized access");
Serial.println();
lcd.setCursor(0,0);
lcd.print("Tag 03");
lcd.setCursor(0,1);
lcd.print("Authorized access");
delay(3000);
}
else if (content.substring(1) == uid4) //change here the UID of the card/cards that you want to give access
{
Serial.println("Authorized access");
Serial.println();
lcd.setCursor(0,0);
lcd.print("Tag 04");
lcd.setCursor(0,1);
lcd.print("Authorized access");
delay(3000);
lcd.clear();
}
else
{
Serial.println(" Access Denied");
lcd.setCursor(3,0);
lcd.clear();
lcd.print("Unknown");
lcd.setCursor(0,1);
lcd.print("Access Denied");
delay(3000);
lcd.clear();
}
*********************************************************************************************************************
if (0.01723 * readUltrasonicDistance(A0, A1) < 20)
{
if (content.substring(1) == uid1)
{
lcd.setCursor(0,0);
lcd.print("Tag 01");
lcd.setCursor(0,1);
lcd.print("Hello Mr.Ahmed");
servo_A2.write(0);
delay(3000);
}
else if (content.substring(1) == uid2) //change here the UID of the card/cards that you want to give access
{
lcd.setCursor(0,0);
lcd.print("Tag 01");
lcd.setCursor(0,1);
lcd.print("Hello Mr.Ali");
servo_A2.write(0);
delay(3000);
}
else
{
Serial.println(" Access Denied");
lcd.setCursor(3,0);
lcd.clear();
lcd.print("Unknown");
lcd.setCursor(0,1);
lcd.print("Access Denied");
delay(3000);
lcd.clear();
servo_A2.write(90);
}
}*/
}