Hi, I've searched all through this forum and google to no avail. I am trying to use an RFID card to open and close a small door. Everything works just fine on the very first loop, but then the RFID scanner (RC522) stops working. It won't detect the same card/tag, or even a different one. I have tried 4 different unique cards and tags and same thing. If I reset the MEGA board via the reset button, it will once again work on the very first try.
Here is a snapshot of my project:
Board: Elegoo Mega
RFID Module: RC522
Exact Physical Wiring As I Have It:
RFID Module Pin Layout (RC522)
SDA - Digital Pin 53
SCK - Digital Pin 52
MOSI - Digital Pin 51
MISO - Digital Pin 50
IRQ - Not Used
GND - GND Pin on Board
RST - Digital Pin 5
3.3V - 3.3V Pin on Board
LCD Display Pin Layout (LCD1602)
VSS - GND on Breadboard
VDD - 5V on Breadboard
VO - Output from 10k Potentiometer
RS - Digital Pin 7
RW - GND on Breadboard
E - Digital Pin 8
D0-D3 - Not Used
D4 - Digital Pin 9
D5 - Digital Pin 10
D6 - Digital Pin 11
D7 - Digital Pin 12
A - 5V on Breadboard
K - GND on Breadboard
10k Potentiometer
Input Pin 1 - 5V on Breadboard
Input Pin 2 - GND on Breadboard
Output Pin 1 - VO on LCD
Switch
Pin 1 - 5V on Breadboard
Pin 2 - GND with 10k Resistor in series
Passive Buzzer
Pin 1 - GND on Breadboard
Pin 2 - Digital Pin 2
Green LED
Pin 1 - GND on Breadboard
Pin 2 - Digital Pin 3 with 200Ohm resistor in series
Red LED
Pin 1 - GND on Breadboard
Pin 2 - Digital Pin 4 with 200Ohm resistor in series
Motor Driver Board (ULN2003)
In1 - Digital Pin 22
In2 - Digital Pin 24
In3 - Digital Pin 26
In4 - Digital Pin 28
Neg - GND on Breadboard
Pos - 5V on Breadboard
ABCD Connector to Stepper Motor (28BYJ-48)
MEGA GND Pin - GND on Breadboard
MEGA 5V Pin - 5V on Breadboard
Here is my Sketch:
#include <MFRC522.h>
// include the library code for the liquid crystal display:
#include <LiquidCrystal.h>
//include the library code for the passive buzzer:
#include "pitches.h"
//include the library code for the stepper motor:
#include <Stepper.h>
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
const int rolePerMinute =17; // Adjustable range of 28BYJ-48 stepper is 0~17 rpm
#define BUZZER 2 //buzzer pin
#define LED_G 3 //define green LED pin
#define LED_R 4 //define red LED
#define RST_PIN 5
#define SS_PIN 53
int Btn = 6;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
// initialize the stepper library on pins 22 through 25:
Stepper myStepper(stepsPerRevolution, 22, 26, 24, 28);
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
pinMode(LED_G, OUTPUT);
pinMode(LED_R, OUTPUT);
pinMode(BUZZER, OUTPUT);
noTone(BUZZER);
pinMode(Btn,INPUT);
Serial.println();
Serial.println("Place your card on reader...");
Serial.println();
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0); // column, row
lcd.print(" Scan Your RFID ");
lcd.setCursor(0,1); // column, row
lcd.print(" Door Closed ");
myStepper.setSpeed(rolePerMinute);
}
void loop() {
// put your main code here, to run repeatedly:
//This code below is for when the button is pressed.
if(digitalRead(Btn) == HIGH){
Serial.println("Access Granted");
Serial.println();
delay(500);
digitalWrite(LED_G, HIGH);
lcd.setCursor(0,1); // column, row
lcd.print(" Door Open ");
tone(BUZZER, 2000);
delay(100);
noTone(BUZZER);
delay(50);
tone(BUZZER, 2000);
delay(100);
noTone(BUZZER);
myStepper.step(stepsPerRevolution);
delay(3000);
myStepper.step(-stepsPerRevolution);
delay(100);
digitalWrite(LED_G, LOW);
lcd.setCursor(0,1); // column, row
lcd.print(" Door Closed ");
tone(BUZZER, 2000);
delay(100);
noTone(BUZZER);
delay(50);
Serial.println("if statement for button...");
}
//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) == "6F 38 63 1E") //change here the UID of card/cards or tag/tags that you want to give access
{
Serial.println("Access Granted");
Serial.println();
delay(500);
digitalWrite(LED_G, HIGH);
lcd.setCursor(0,1); // column, row
lcd.print(" Door Open ");
tone(BUZZER, 2000);
delay(100);
noTone(BUZZER);
delay(50);
tone(BUZZER, 2000);
delay(100);
noTone(BUZZER);
myStepper.step(stepsPerRevolution);
delay(4000);
myStepper.step(-stepsPerRevolution);
delay(4000);
digitalWrite(LED_G, LOW);
lcd.setCursor(0,1); // column, row
lcd.print(" Door Closed ");
tone(BUZZER, 2000);
delay(100);
noTone(BUZZER);
delay(50);
Serial.println();
Serial.println("Place your card on reader...");
Serial.println();
}
else
{
lcd.setCursor(0,1); // column, row
lcd.print("Invalid RFID Tag");
Serial.println(" Access denied");
digitalWrite(LED_R, HIGH);
tone(BUZZER, 1500);
delay(500);
digitalWrite(LED_R, LOW);
noTone(BUZZER);
delay(100);
digitalWrite(LED_R, HIGH);
tone(BUZZER, 1500);
delay(500);
digitalWrite(LED_R, LOW);
noTone(BUZZER);
delay(100);
digitalWrite(LED_R, HIGH);
tone(BUZZER, 1500);
delay(500);
digitalWrite(LED_R, LOW);
noTone(BUZZER);
lcd.setCursor(0,1); // column, row
lcd.print(" Door Closed ");
Serial.println();
Serial.println("Place your card on reader...");
Serial.println();
}
}
Here is an example of what is shown in the Serial Monitor Window after running it once:
Place your card on reader...
UID tag : 6F 38 63 1E
Message : Access Granted
Place your card on reader...
After this point, like I mentioned it will no longer scan another card or tag. It's hung up somewhere and I can't figure out where it is. Thanks for any advice.

