Hello I have project with arduino IDE program that used C language ... I’m using
ID: 3706681 • Letter: H
Question
Hello I have project with arduino IDE program that used C language ... I’m using Arduino Uno and RFID RC522 to read a card .. this project work when I scan the card on reader ... So, now I have a code but I need to explaination to know how it’s work ?// why we need this library ??
#include <MFRC522.h>
#include <SPI.h>
// why define this pin only? ( RFID RC522 has 8 pins)
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
//The card_ID[4] used for what ? And why the card write in this method {0x56,0x4d,0x47,0xFF} ?
byte card_ID[4];
byte First_card_ID[4]={0x56,0x4d,0x47,0xFF};
byte i;
// why using the Boolean and why it’s false ?
boolean State = false; Void setup {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
}
// I need explaining to how this function done step by step
void crd_id(){
for (byte i = 0; i < mfrc522.uid.size; i++) {
if(card_ID[i]==First_card_ID[i]){
State=true;
}
else{
State=false;
i=5;
}
}
}
Finally, I want to add another card that can be read card and accepted
Regards,
Hello I have project with arduino IDE program that used C language ... I’m using Arduino Uno and RFID RC522 to read a card .. this project work when I scan the card on reader ... So, now I have a code but I need to explaination to know how it’s work ?
// why we need this library ??
#include <MFRC522.h>
#include <SPI.h>
// why define this pin only? ( RFID RC522 has 8 pins)
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
//The card_ID[4] used for what ? And why the card write in this method {0x56,0x4d,0x47,0xFF} ?
byte card_ID[4];
byte First_card_ID[4]={0x56,0x4d,0x47,0xFF};
byte i;
// why using the Boolean and why it’s false ?
boolean State = false; Void setup {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
}
// I need explaining to how this function done step by step
void crd_id(){
for (byte i = 0; i < mfrc522.uid.size; i++) {
if(card_ID[i]==First_card_ID[i]){
State=true;
}
else{
State=false;
i=5;
}
}
}
Finally, I want to add another card that can be read card and accepted
Regards,
Hello I have project with arduino IDE program that used C language ... I’m using Arduino Uno and RFID RC522 to read a card .. this project work when I scan the card on reader ... So, now I have a code but I need to explaination to know how it’s work ?
// why we need this library ??
//The card_ID[4] used for what ? And why the card write in this method {0x56,0x4d,0x47,0xFF} ?
byte card_ID[4];
byte First_card_ID[4]={0x56,0x4d,0x47,0xFF};
byte i;
// why using the Boolean and why it’s false ?
boolean State = false; Void setup {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
}
// I need explaining to how this function done step by step
void crd_id(){
for (byte i = 0; i < mfrc522.uid.size; i++) {
if(card_ID[i]==First_card_ID[i]){
State=true;
}
else{
State=false;
i=5;
}
}
}
//The card_ID[4] used for what ? And why the card write in this method {0x56,0x4d,0x47,0xFF} ?
byte card_ID[4];
byte First_card_ID[4]={0x56,0x4d,0x47,0xFF};
byte i;
// why using the Boolean and why it’s false ?
boolean State = false; Void setup {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
}
// I need explaining to how this function done step by step
void crd_id(){
for (byte i = 0; i < mfrc522.uid.size; i++) {
if(card_ID[i]==First_card_ID[i]){
State=true;
}
else{
State=false;
i=5;
}
}
}
Void setup {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
}
// I need explaining to how this function done step by step
void crd_id(){
for (byte i = 0; i < mfrc522.uid.size; i++) {
if(card_ID[i]==First_card_ID[i]){
State=true;
}
else{
State=false;
i=5;
}
}
}
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
}
// I need explaining to how this function done step by step
void crd_id(){
for (byte i = 0; i < mfrc522.uid.size; i++) {
if(card_ID[i]==First_card_ID[i]){
State=true;
}
else{
State=false;
i=5;
}
}
}
Finally, I want to add another card that can be read card and accepted
Regards,
Explanation / Answer
Why we need library ??
The Arduino environment is extended with the use of libraries, same like most programming platforms. Library provides extra functionality for use in user code, for example working with hardware or manipulating data.
A number of libraries are installed within IDE as inbuilt, but we can also download or create on our own
<SPI.h> is used for communicating with devices using the Serial Peripheral Interface (SPI)
<MFRC522.h> is used to acces the features of the module and make it fully functional.
The MFRC522 is a efficiently integrated writer/reader IC for contactless communication at 13.56 MHz
The MFRC522’s internal transmitter is able to drive a writer/reader antenna designed to communicate with ISO/IEC 14443 A/MIFARE cards & transponders without the use of any additional active circuitry.
The receiver module provides a efficient and robust implementation for demodulating and decoding signals from ISO/IEC 14443 A/MIFARE compatible transponders and cards.
The digital module mostly manages with the complete ISO/IEC 14443A framing and error detection i.e parity and Cyclic Redundancy Check functionality.
This module is worked with the following communications:
• Serial Peripheral Interface (SPI)
• Serial UART (similar to RS232 with voltage levels dependant on pin voltage supply)
• I2C-bus interface
Why define this pin only?
Pin 9 represents symbol is SVDD - MFIN and MFOUT pin power supply
Pin 10 represents symbol is TVSS - transmitter output stage 1 ground
The card_ID[4] used for what?
byte card_id[4] is an array of 4 card id's
The card write these characters in the array on the card for authentication {0x56,0x4d,0x47,0xFF)
why using the Boolean and why it’s false ?
Initially th state of the module will be false, one there is an activity started by the user regarding authentication the state of the module will be true.
Given Code:
void crd_id(){
for (byte i = 0; i < mfrc522.uid.size; i++) {
if(card_ID[i]==First_card_ID[i]){
State=true;
}
else{
State=false;
i=5;
}
}
- void crd_id() is the method defined with name "crd_id".
- for loop read the data given in the array of characters which are used to read the card.
- card_id[i] reads the value of card id's and compares with the values with characters stored in the module for authentication purpose.
- if(card_ID[i]==First_card_ID[i]) if this statement is true then the boolean state is changed to true
- Else if (card_ID[i]!=First_card_ID[i]) then the state boolean continuous to be in the state of false an therefore if reprepresents that authentication is false.
- As the limit of the array is 4 the variable i takes the value as 5 and ends the for loop
I want to add another card that can be read card and accepted
You can add any number of cards but the characters set given in the byte First_card_ID[4] should not be given for another card.
You can add other by declaring the variable byte Second_card_ID[4] ={with some character data set}
you should modify the for loop to read multiple cards data.
thus you can add any number of cards
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.