RFID to comand 2 relays

For the discussion of Arduino related topics.

Moderator: phalanx

Post Reply
IRSantos8
Posts: 1
Joined: Tue Aug 01, 2017 7:57 am

RFID to comand 2 relays

Post by IRSantos8 » Tue Aug 01, 2017 8:02 am

Hi guys, so my objective is to open with the first card swipe reading, and close with the second same card swipe, as is when I swipe the card it sends the signal to relay 1 to open, and half a second later to the second to close...I would like to send the comand to close only with a second card swipe

if someone can help me i would thank you


this is what I have so far:

Code: Select all


#include <SPI.h>
#include <MFRC522.h>
 
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
#define RELAY1  6
#define RELAY2  5
 
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();
  
}
void loop() 
{
  // Initialise the Arduino data pins for OUTPUT

  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT);
  
  // 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) == "83 9B B1 AB" || content.substring(1) == "16 AF 86 A5") //change here the UID of the card/cards that you want to give access
  {
    Serial.println("Open");
    Serial.println();
    delay(100);
    digitalWrite(RELAY1,HIGH);           // Turns ON Relay 1
    delay(500);                                      // Wait 1\2 second
    digitalWrite(RELAY1,LOW);          // Turns Relay Off
  }

 else (content.substring(1) == "83 9B B1 AB" || content.substring(1) == "16 AF 86 A5") //change here the UID of the card/cards that you want to give access
;  {
    Serial.println("Closed");
    Serial.println();
    delay(100);
    digitalWrite(RELAY2,HIGH);           // Turns ON Relay 2
    delay(500);                                      // Wait 1\2 second
    digitalWrite(RELAY2,LOW);          // Turns Relay Off
  }
 }

Post Reply