i'm having trouble with writing code, i'm trying to self teach myself, but its not good well. have hacked bits of different code together,to make my alarm system project but i cant figure out how to add more then one RFID tag to the code. is it possible that someone can give us a hand trying to sort it thanks.
this is what have.
/*
Typical pin layout used:
-----------------------------------------------------------------------------------------
MFRC522 Arduino Arduino
Reader/PCD Uno/101 Nano v3
Signal Pin Pin Pin
-----------------------------------------------------------------------------------------
RST/Reset RST 9 D9 orange
SPI SS SDA(SS) 10 D10 yellow
SPI MOSI MOSI 11 / ICSP-4 D11 green
SPI MISO MISO 12 / ICSP-1 D12 blue
SPI SCK SCK 13 / ICSP-3 D13 purple
*/
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
int RELAY = 8;
int REDLED = 7;
int GREENLED = 6;
int BUZZER = 5;
void setup()
{
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("SHED DOOR.");
Serial.println();
pinMode (RELAY, OUTPUT);
pinMode (REDLED, OUTPUT);
pinMode (GREENLED, OUTPUT);
pinMode (BUZZER, OUTPUT);
}
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) == "85 A5 B0 56") //change here the UID of the card/cards that you want to give access
{
Serial.println("Authorized access");
Serial.println("Welcome Mr Hughes");
digitalWrite (BUZZER, HIGH);
delay(500);
digitalWrite (BUZZER, LOW);
digitalWrite (RELAY, HIGH);
digitalWrite (GREENLED, HIGH);
delay(10000);
digitalWrite (RELAY, LOW);
digitalWrite (GREENLED, LOW);
}
else {
Serial.println(" Access denied");
digitalWrite (REDLED, HIGH);
delay(3000);
digitalWrite (REDLED, LOW);
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.