Need Help with RFID

Hi,
I have a system where a RFID is making 2 servo motors move 180 degrees. But at the moment I have a delay for the motors and I don’t know how to have the motors on wile the card is present and when the card is removed the motor moves to its original position (0 degrees).
thanks :slight_smile:

Hi, can you share the code you are working on ?

Cheers,

Maayan

This is my Code:

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>

#define SS_PIN 10
#define RST_PIN 9
#define LED_G 4 //define green LED pin
#define LED_R 5 //define red LED
#define BUZZER 2 //buzzer pin
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
Servo myServo1; //define servo name
Servo myServo2;

void setup()
{
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
myServo1.attach(3); //servo pin
myServo1.write(0); //servo start position
myServo2.attach(6);
myServo2.write(180);
pinMode(LED_G, OUTPUT);
pinMode(LED_R, OUTPUT);
pinMode(BUZZER, OUTPUT);
noTone(BUZZER);
Serial.println(“Put your card to the reader…”);
Serial.println();

}
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) == “41 A3 DE DB”||content.substring(1) == “D5 64 BF B0”) //change here the UID of the card/cards that you want to give access
{
Serial.println(“Authorized access”);
Serial.println();
delay(500);
digitalWrite(LED_G, HIGH);
tone(BUZZER, 500);
delay(300);
noTone(BUZZER);
myServo1.write(180);
myServo2.write(0);
delay(5000);
myServo1.write(0);
myServo2.write(180);
digitalWrite(LED_G, LOW);
}

else {
Serial.println(" Access denied");
digitalWrite(LED_R, HIGH);
tone(BUZZER, 300);
delay(1000);
digitalWrite(LED_R, LOW);
noTone(BUZZER);
}
}

Hope to hear back from you and/or others