Can i use this code for run 2 rfid with arduino mega ? please help!

#include <SPI.h>

#include <MFRC522.h>

#define SS_PIN 10
#define SS_2_PIN 11
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
MFRC522 mfrc522_2(SS_2_PIN, RST_PIN);// Create MFRC522 instance.
int count = 0;
int count2 = 0;
void setup()
{
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
mfrc522_2.PCD_Init(); // Initiate MFRC522

Serial.println("Put your card to the reader for scanning …");
Serial.println();

}
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();

String value1 = content.substring(1);
if ( value1 == ("AB CD EF GH") )// enter your own card number after copying it from serial monitor
{
count = count+1;
}
else{}

switch (count)
{
case 1:
if ( digitalRead(4)==0,digitalRead(6)==0,digitalRead(7)==0)
{
for(int i = 0;i<255;i++)
digitalWrite(5,i);
digitalWrite(8,HIGH);
delay(500);
digitalWrite(8,LOW);
}
else{}
break;
case 2:
digitalWrite(8,HIGH);
delay(500);
digitalWrite(8,LOW);
delay(1000);
count=count-2;
break;
}

// Look for new cards
if ( ! mfrc522_2.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522_2.PICC_ReadCardSerial())
{
return;
}
Serial.print("2_UID tag :");
String content2 = "";
byte letter2;
for (byte i = 0; i < mfrc522_2.uid.size; i++)
{
Serial.print(mfrc522_2.uid.uidByte[i] < 0x10 ? " 0″": " ");
Serial.print(mfrc522_2.uid.uidByte[i], HEX);
content2.concat(String(mfrc522_2.uid.uidByte[i] < 0x10 ? " 0" : " "));
content2.concat(String(mfrc522_2.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content2.toUpperCase();
String value2 = content2.substring(1);
if ( value2 == ("AB CD EF GH") )// enter your own card number after copying it from serial monitor
{
count2 = count2+1;
}
else{}

switch (count)
{
case 1:
if ( digitalRead(14)==0,digitalRead(15)==0,digitalRead(16)==0)
{
for(int i = 0;i<255;i++)
digitalWrite(17,i);
digitalWrite(8,HIGH);
delay(500);
digitalWrite(8,LOW);
}
else{}
break;
case 2:
digitalWrite(9,HIGH);
delay(500);
digitalWrite(9,LOW);
delay(1000);
count2=count2-2;
break;
}
}

Work through this…
I don’t think it’s going to do what you’re expecting.

PLUS, forum etiquette asks that you read the guides, and post code appropriately in code tags.

I don't know about code tags so..

This code is example , i will do other operation .

I don't know about code tags so..

Then you obviously haven’t read the forum guidelines.

There are a lot of people here that want to help, but the harder you make it, the less help you’ll get.

Sorry, harsh truth.

1 Like

You can spend about 3 or 4 weeks playing the guessing game, or you give up unless you get lucky. Code tages and an annotated schematic will probably cut that to 2 or 3 days for a solid answer, many times less than a day. If you can read it should take less than 1/2 hour to read the guidelines. That will save us hours like many of us , me included will not take the time to play the game. There are a lot of excuses for not doing a schematic but great tools are available free but it will take a bit of learning on your end to use them.

Post the schematic as you have it wired, not a fritzing diagram and include links to technical information on the hardware items including the board etc. For all I know you could be trying to run this on a PDP11.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.