Update src/arduino/card_scanner.ino

main
Eyuep Sueyruege 2023-11-14 16:13:44 +01:00
parent f2543ffbff
commit b71654f673
1 changed files with 12 additions and 14 deletions

View File

@ -1,29 +1,22 @@
// imports // imports
#include <SPI.h> #include <SPI.h>
#include <MFRC522.h> #include <MFRC522.h>
#include <Servo.h>
#include <Wire.h>
// Pin Definition // Pin Definition
#define SS_PIN 10 #define SS_PIN 10
#define RST_PIN 9 #define RST_PIN 9
// Instatiate Motor and RFID Module // Instatiate Motor and RFID Module
Servo motor;
MFRC522 rfid(SS_PIN, RST_PIN); MFRC522 rfid(SS_PIN, RST_PIN);
byte nuidPICC[4];
// Setup for first time // Setup for first time
void setup() { void setup() {
// Serial Begin // Serial Begin
Serial.begin(9600); Serial.begin(9600);
// Servo Attach
motor.attach(6);
// Pin Setting
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
// Init SPI bus // Init SPI bus
SPI.begin(); SPI.begin();
// Init MFRC522 // Init MFRC522
@ -32,7 +25,7 @@ void setup() {
// iteration // iteration
void loop() { void loop() {
// Reset the loop if no new card present on the reader // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if (!rfid.PICC_IsNewCardPresent()){ if (!rfid.PICC_IsNewCardPresent()){
return; return;
} }
@ -40,9 +33,14 @@ void loop() {
if (!rfid.PICC_ReadCardSerial()){ if (!rfid.PICC_ReadCardSerial()){
return; return;
} }
for (byte i = 0; i < 4; i++) {
nuidPICC[i] = rfid.uid.uidByte[i];
}
String id = "ID: "+String(nuidPICC[0])+" : "+String(nuidPICC[1])+" : "+String(nuidPICC[2])+" : "+String(nuidPICC[3]);
Serial.println(id);
// Send UID of token to the serialport
Serial.println(rfid.uid)
delay(1000); delay(1000);
@ -52,4 +50,4 @@ void loop() {
// Stop encryption on PCD // Stop encryption on PCD
rfid.PCD_StopCrypto1(); rfid.PCD_StopCrypto1();
} }