Hi all,
I hope you can help me with my project. I want to do the following:
I want to be able to open my sliding door with an RFID tag. Currently the sliding door opens only with a remote control. I figured out that can connect a relay parrallel to the receiver unit on the sliding controlboard to be able to open the door with remote and with RFID. After opening the door with RFID, i want to be able to close it with a pushbutton (non-stick). I have edited existing code so that the relay closes when the right TAG is presented but i can't seem to figure out how to implement the pushbutton into the code. It seems the code runs over the last part and opens the relay despite the pushbutton not pushed. I used the println to print the value of the PUSHBUTTON, it displays the right value, so its not a problem with reading the pushbutton value.
My Code:
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
int REDLED = 2;
int RELAY = 3;
int PUSHBUTTON = 0;
void setup()
{
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.print("SHED DOOR.");
pinMode (REDLED, OUTPUT);
pinMode (RELAY, OUTPUT);
pinMode (PUSHBUTTON, INPUT);
}
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) == "14 6C B9 A7" || content.substring(1) == "14 99 1B A7" ) //change here the UID of the card/cards that you want to give access
{
Serial.println("Authorized access");
digitalWrite (RELAY, HIGH);
}
else {
Serial.println(" Access denied");
digitalWrite (RELAY, LOW);
}
PUSHBUTTON = digitalRead (7);
Serial.print(PUSHBUTTON);
if (PUSHBUTTON = LOW){
digitalWrite (RELAY, LOW);
}
}
I hope you guys can help me