Hello everyone,
im a really new in Arduino World. I would be really happy, if you guys can help me out to for my school project. Im trying to make a security system with RFID and LED. It is actually really simple but im not sure how should i change my Code. I have already a code that works. I can light the greed led up, if i use the right card. If i use the second card the red goes on. But i want to upgrade it. If i show the right card i need to get green led goes on otherwise red. I need the change it with else commend. But i have no idea how i do it. I wrote my all code here so you can guys see, what i reached. But i cant go far more then. I would be really happy if you guys can help me
#include <SPI.h>
#include <MFRC522.h>
#define PIN_RESET 5 // SPI Reset Pin
#define PIN_SS 53 // SPI Slave Select Pin
#define PIN_LED_GREEN 2
#define PIN_LED_RED 7
MFRC522 mfrc522(PIN_SS, PIN_RESET);
bool isGreen, isRed;
// insert the IDs of your personal NFC tags
byte uidGreen[] = {0xDB, 0x7F, 0xEA, 0xD5};
byte uidRed[] = {0x3A, 0x56, 0xDA, 0x29};
void setup()
{
SPI.begin();
mfrc522.PCD_Init();
pinMode(PIN_LED_GREEN, OUTPUT);
pinMode(PIN_LED_RED, OUTPUT);
}
void loop()
{
// PICC = proximity integrated circuit card
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
isGreen = true;
isRed = true;
for (byte i=0; i<4; i++) {
if (mfrc522.uid.uidByte[i] != uidGreen[i]) {
isGreen = false;
}
if (mfrc522.uid.uidByte[i] != uidRed[i]) {
isRed = false;
}
}
if (isGreen) {
digitalWrite(PIN_LED_GREEN, HIGH);
}
if (isRed) {
digitalWrite(PIN_LED_RED, HIGH);
}
mfrc522.PICC_HaltA();
delay(1000);
digitalWrite(PIN_LED_GREEN, LOW);
digitalWrite(PIN_LED_RED, LOW);
}
}