Quantcast
Channel: Sensors - Arduino Forum
Viewing all articles
Browse latest Browse all 1072

Rc522 disable when bike starts or horn blowse

$
0
0

When I was start bike or blow horn then rc522 was disable I was trying shielding or use dc to dc isolator to isolate Arduino and sensor from battery of bike and also use inductor or x2 capacitor but it isn't work so what should I do?

                                                             
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
#define LED_PIN_CORRECT 3
#define LED_PIN_WRONG 2

MFRC522 mfrc522(SS_PIN, RST_PIN);

// Define the correct card UID
byte correctCardUID[] = {0x23, 0x10, 0xC1, 0x1A, 0xEE};

void setup() {
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  
  pinMode(LED_PIN_CORRECT, OUTPUT);
  pinMode(LED_PIN_WRONG, OUTPUT);
}

void loop() {
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
    byte buffer[4];
    memcpy(buffer, mfrc522.uid.uidByte, 4);

    if (compareUID(buffer, correctCardUID)) {
      blinkLED(LED_PIN_CORRECT, 1); // Blink once for correct card
    } else {
      blinkLED(LED_PIN_WRONG, 5); // Blink 5 times for wrong card
      Serial.print("Wrong card UID: ");
      printUID(buffer); // Print UID of the wrong card
      Serial.println();
    }

    mfrc522.PICC_HaltA();
    mfrc522.PCD_StopCrypto1();
  }
}

bool compareUID(byte* uid1, byte* uid2) {
  for (int i = 0; i < 4; i++) {
    if (uid1[i] != uid2[i]) {
      return false;
    }
  }
  return true;
}

void blinkLED(int pin, int count) {
  for (int i = 0; i < count; i++) {
    digitalWrite(pin, HIGH);
    delay(500);
    digitalWrite(pin, LOW);
    delay(500);
  }
}

void printUID(byte* uid) {
  for (int i = 0; i < 4; i++) {
    Serial.print(uid[i], HEX);
    Serial.print(" ");
  }
}

9 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 1072

Trending Articles