/*
Arduino | Coding-help
NeoPixel Ring stops MFRC522 RFID reader from reading
hhero - Sunday, April 5, 2026 8:54 AM
Hey everyone, I’m working on an Arduino Mega
+ MFRC522 RFID reader + 24-LED NeoPixel ring setup
and I’m running into a weird timing issue I can’t solve.
*/
#include <SPI.h>
#include <MFRC522.h>
#include <Adafruit_NeoPixel.h>
#define RST_PIN 5
#define SS_PIN 53
#define IDLE_LED 7
#define CORRECT_LED 8
#define WRONG_LED 6
#define PIXEL_PIN 9
#define NUMPIXELS 24
MFRC522 mfrc522(SS_PIN, RST_PIN);
Adafruit_NeoPixel ring(NUMPIXELS, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
// Correct UID
//byte correctUID[] = {0xA1, 0x96, 0x69, 0x06};
byte correctUID[] = {0x01, 0x02, 0x03, 0x04};
byte uidLength = 4;
// track current color
uint8_t currentR = 255;
uint8_t currentG = 150;
uint8_t currentB = 0;
uint16_t chaseIndex = 0;
unsigned long lastFrame = 0;
void runIdleAnimation() {
if (millis() - lastFrame < 80) return;
lastFrame = millis();
for (int i = 0; i < NUMPIXELS; i++) {
ring.setPixelColor(i, ring.Color(10, 5, 0));
}
ring.setPixelColor(chaseIndex, ring.Color(255, 150, 0));
ring.show();
chaseIndex++;
if (chaseIndex >= NUMPIXELS) chaseIndex = 0;
}
// smooth fade function
void fadeToColor(uint8_t r, uint8_t g, uint8_t b) {
int steps = 40;
for (int i = 0; i <= steps; i++) {
uint8_t newR = currentR + (r - currentR) * i / steps;
uint8_t newG = currentG + (g - currentG) * i / steps;
uint8_t newB = currentB + (b - currentB) * i / steps;
for (int p = 0; p < NUMPIXELS; p++) {
ring.setPixelColor(p, newR, newG, newB);
}
ring.show();
delay(10);
}
currentR = r;
currentG = g;
currentB = b;
}
bool compareUID(byte *uid1, byte *uid2) {
for (byte i = 0; i < uidLength; i++) {
if (uid1[i] != uid2[i]) return false;
}
return true;
}
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
pinMode(IDLE_LED, OUTPUT);
pinMode(CORRECT_LED, OUTPUT);
pinMode(WRONG_LED, OUTPUT);
ring.begin();
ring.show();
fadeToColor(255, 150, 0); // start yellow idle
Serial.println("Plate reader ready.");
}
void loop() {
digitalWrite(IDLE_LED, HIGH);
digitalWrite(CORRECT_LED, LOW);
digitalWrite(WRONG_LED, LOW);
if (!mfrc522.PICC_IsNewCardPresent()) {
runIdleAnimation();
return;
Serial.println("hi");
}
Serial.println("2");
if (!mfrc522.PICC_ReadCardSerial()) return;
Serial.println("Tag detected");
digitalWrite(IDLE_LED, LOW);
if (compareUID(mfrc522.uid.uidByte, correctUID)) {
Serial.println("Correct plant");
digitalWrite(CORRECT_LED, HIGH);
fadeToColor(0, 255, 0);
}
else {
Serial.println("Wrong plant");
digitalWrite(WRONG_LED, HIGH);
fadeToColor(255, 0, 0);
}
delay(1500);
digitalWrite(IDLE_LED, HIGH);
digitalWrite(CORRECT_LED, LOW);
digitalWrite(WRONG_LED, LOW);
fadeToColor(255, 150, 0);
mfrc522.PICC_HaltA();
}
Loading
mfrc522
mfrc522