I am totally new to Arduino programming an I am I need of some help. I am needing help with some code. What we are trying to do is use 5 RFID readers that the correct card has to be placed on the correct reader to unlock a magnetic lock. Which card is placed 1st doesn't matter just as long a the correct on is placed in the correct spot. My friend has done this using 3 RFID but we are not for sure what needs to be added for 5
Just change 3 to 5. Ask your friend for help.
Friend has changed it but for some reason it isn't stable works great a few times then has problems do you have a sample sketch for this or anyone else have that would share ?
It's doubtful that anyone has done this. As you know, usually there is only one reader required. So you are on your own. Your best bet is to post the code so we can see it.
here is code he has
/**
-
Typical pin layout used:
-
-
MFRC522 Arduino Arduino Arduino Arduino Arduino
-
Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
-
Signal Pin Pin Pin Pin Pin Pin
-
-
RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
-
SPI SS 1 SDA(SS) ** custom, take a unused pin, only HIGH/LOW required **
-
SPI SS 2 SDA(SS) ** custom, take a unused pin, only HIGH/LOW required **
-
SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
-
SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
-
SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*/
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_1_PIN 10 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
#define SS_2_PIN 8 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1
#define SS_3_PIN 7 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1
#define NR_OF_READERS 3
byte ssPins[] = {SS_1_PIN, SS_2_PIN,SS_3_PIN};
MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
String read_rfid;
String ValidCard_1 = "8cc1ad85";
String ValidCard_2 = "5efc1f2b";
String ValidCard_3 = "1196b85";
boolean Card_1_ok = false;
boolean Card_2_ok = false;
boolean Card_3_ok = false;
int Read1 = 9;
int Read2 = 9;
boolean ValidCardOrder = true;
String Prevcard = "";
int NoCardCnt = 0;
int DoorLockPin = 4;
int DoorOpenSec = 2;
/**
- Initialize.
*/
void setup() {
pinMode(DoorLockPin,OUTPUT);
digitalWrite(DoorLockPin,HIGH);
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
Serial.print(F("Reader "));
Serial.print(reader);
Serial.print(F(": "));
mfrc522[reader].PCD_DumpVersionToSerial();
}
}
/**
- Main loop.
*/
void loop() {
if (NoCardCnt > 150){
Card_1_ok = false;
Card_2_ok = false;
Card_3_ok = false;
ValidCardOrder = true;
digitalWrite(DoorLockPin,HIGH);
NoCardCnt = 0;
Prevcard = "";
Read1 = 9;
Read2 = 9;
}
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Look for new cards
//
//Serial.println("Reading readers" + String(ValidCardOrder) + "-----" + String(Card_1_ok) + "--" + String(Card_2_ok) + "--" + String(Card_3_ok));
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
Serial.print(F("Reader "));
Serial.print(reader);
// Show some details of the PICC (that is: the tag/card)
dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
Serial.println(read_rfid);
ValidateCard(reader);
// Halt PICC
mfrc522[reader].PICC_HaltA();
// Stop encryption on PCD
mfrc522[reader].PCD_StopCrypto1();
}
else{
NoCardCnt = NoCardCnt + 1;
delay(50);
//Serial.println("No card on sensor cnt" + String(NoCardCnt));
}
}
}
void dump_byte_array(byte *buffer, byte bufferSize) {
read_rfid = "";
for (byte i = 0; i < bufferSize; i++) {
read_rfid = read_rfid + String(buffer*, HEX);*
-
}*
}
void ValidateCard(int reader) { -
if (reader == Read1) {*
-
Serial.println("Reader 1 already reads");*
-
goto GoNext;}*
-
if (reader == Read2) {*
-
Serial.println("Reader 2 already reads"); *
-
goto GoNext;}*
-
int x;*
-
Prevcard = read_rfid;*
-
if (Card_1_ok == false && Card_2_ok == false && Card_3_ok == false){*
-
if (ValidCard_1 == read_rfid){*
-
Read1 = reader;*
-
Card_1_ok = true;*
-
NoCardCnt = 0;*
-
goto GoNext; *
-
}*
-
else{*
-
ValidCardOrder = false;*
-
goto GoNext; *
-
}*
-
}*
-
if (Card_1_ok == true && Card_2_ok == false && Card_3_ok == false){*
-
if (ValidCard_2 == read_rfid){*
-
Read2 = reader;*
-
Card_2_ok = true;*
-
NoCardCnt = 0;*
-
goto GoNext; *
-
}*
-
else{*
-
ValidCardOrder = false;*
-
goto GoNext; *
-
}*
-
}*
-
if (Card_1_ok == true && Card_2_ok == true && Card_3_ok == false){*
-
if (ValidCard_3 == read_rfid){*
-
Card_3_ok = true; *
-
if (ValidCardOrder) {*
-
open_lock(); *
-
} *
-
}*
-
else{*
-
ValidCardOrder = false; *
-
}*
-
}*
*GoNext: *
- x = 0;*
} *
void open_lock(){
_ //Serial.println("***************************************** Door opened");_
- digitalWrite(DoorLockPin,LOW);*
_ delay(DoorOpenSec*1000);_ - digitalWrite(DoorLockPin,HIGH);*
- Card_1_ok = false;*
- Card_2_ok = false;*
- Card_3_ok = false; *
- ValidCardOrder = true;*
- NoCardCnt = 0;*
- Prevcard = "";*
*} *
Welcome to the Forum. Please read the posts:
How to use this forum - please read. and
Read this before posting a programming question ...
You have posted code without using code tags. The code tags make the code look
like this
when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.