So guys,
This is my very first topic, and I'm really embarrassed about this situation.
Really Asking for help !!!!
I have two projects: 4 and 9 RFIDs next to each other ( RFID RC522). If all of them has the token nearby, so a maglock will open.
Sound simple, but i faced a huge problem here :((((
The first problem it was after the first test i realized that my Cards NOT working. Neither of them. Only the tokens. Well, this was not a big issue for me, because anyway, i wanted to use my tokens only. But it was REALLY strange ... Anyway, I made this program, and i can't make the sensor range more than 8mm ??? I mean, what is happening here? As i know the RFID token must be working max 6cm !!!! , and i can't even go further than 1 cm.
First, i thought i have a hardware problem... I bought different Arduinos and sensors, but i have exactly the same problem here.
Now i think i have an issue with my program ... Can anyone help me, please ? I would really appreciate it
Here is the program:
#include <SPI.h>
#include <MFRC522.h>
#include <Keypad.h>
#define RST_PIN 9
#define SS_1_PIN 10
#define SS_2_PIN 8
#define SS_3_PIN 7
#define SS_4_PIN 6
#define NR_OF_READERS 4
byte ssPins[] = {SS_1_PIN, SS_2_PIN, SS_3_PIN, SS_4_PIN};
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int rele = 5;
const byte ROWS = 1; //four rows
const byte COLS = 1; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1'}
};
byte rowPins[ROWS] = {2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {3}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
/**
Initialize.
*/
void setup() {
Serial.begin(115200); // Initialize serial communications with the PC
//while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
pinMode(rele, OUTPUT);
digitalWrite(rele, HIGH);
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
mfrc522.PCD_SetRegisterBitMask(mfrc522.RFCfgReg, (0x07<<4));
}
}
void loop()
{
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++)
{
// Look for new cards
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial())
{
Serial.print(F("Reader "));
Serial.print(reader);
Serial.println(F(":"));
// Show some details of the PICC (that is: the tag/card)
Serial.print(F("Card UID:"));
dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
Serial.println();
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));
Serial.println();
if (mfrc522[reader].uid.uidByte[0] == 22 &
mfrc522[reader].uid.uidByte[1] == 112 &
mfrc522[reader].uid.uidByte[2] == 38 &
mfrc522[reader].uid.uidByte[3] == 126 &
reader == 0 )
{
Serial.println(F("0-s kartya oke"));
a++;
}
if (mfrc522[reader].uid.uidByte[0] != 22 &
mfrc522[reader].uid.uidByte[1] != 112 &
mfrc522[reader].uid.uidByte[2] != 38 &
mfrc522[reader].uid.uidByte[3] != 126 &
reader == 0)
{
Serial.println(F("nem 0-s kartya"));
a = 0;
}
if (mfrc522[reader].uid.uidByte[0] == 86 &
mfrc522[reader].uid.uidByte[1] == 220 &
mfrc522[reader].uid.uidByte[2] == 36 &
mfrc522[reader].uid.uidByte[3] == 126 &
reader == 1 )
{
Serial.println(F("1-es kartya oke"));
b++;
}
if (mfrc522[reader].uid.uidByte[0] != 86 &
mfrc522[reader].uid.uidByte[1] != 220 &
mfrc522[reader].uid.uidByte[2] != 36 &
mfrc522[reader].uid.uidByte[3] != 126 &
reader == 1 )
{
Serial.println(F("nem 1-s kartya"));
b = 0;
}
if (mfrc522[reader].uid.uidByte[0] == 134 &
mfrc522[reader].uid.uidByte[1] == 57 &
mfrc522[reader].uid.uidByte[2] == 25 &
mfrc522[reader].uid.uidByte[3] == 126 &
reader == 2 )
{
Serial.println(F("2-es kartya oke"));
c++;
}
if (mfrc522[reader].uid.uidByte[0] != 134 &
mfrc522[reader].uid.uidByte[1] != 57 &
mfrc522[reader].uid.uidByte[2] != 25 &
mfrc522[reader].uid.uidByte[3] != 126 &
reader == 2 )
{
Serial.println(F("nem 2-s kartya"));
c = 0;
}
if (mfrc522[reader].uid.uidByte[0] == 06 &
mfrc522[reader].uid.uidByte[1] == 106 &
mfrc522[reader].uid.uidByte[2] == 34 &
mfrc522[reader].uid.uidByte[3] == 126 &
reader == 3 )
{
Serial.println(F("3-es kartya oke"));
d++;
}
if (mfrc522[reader].uid.uidByte[0] != 06 &
mfrc522[reader].uid.uidByte[1] != 106 &
mfrc522[reader].uid.uidByte[2] != 34 &
mfrc522[reader].uid.uidByte[3] != 126 &
reader == 3 )
{
Serial.println(F("nem 3-s kartya"));
d = 0;
}
Serial.println();
// Halt PICC
mfrc522[reader].PICC_HaltA();
// Stop encryption on PCD
mfrc522[reader].PCD_StopCrypto1();
} //if (mfrc522[reader].PICC_IsNewC
} //for(uint8_t reader
if (a > 0 & b > 0 & c > 0 & d > 0)
{
char key = customKeypad.getKey();
digitalWrite(rele, LOW);
Serial.println("NYITVA");
if(key == '1')
{
Serial.println("ZÁRVA");
digitalWrite(rele, HIGH);
a = 0;
b = 0;
c = 0;
d = 0;
}
}
}
/**
Helper routine to dump a byte array as hex values to Serial.
/
void dump_byte_array(byte buffer, byte bufferSize)
{
for (byte i = 0; i < bufferSize; i++)
{
Serial.print(buffer < 0x10 ? " 0" : " ");
_ Serial.print(buffer, DEC);_
* }*
}