Advertisement
pleasedontcode

RFID Scanner rev_02

May 9th, 2024
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: RFID Scanner
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-05-09 10:56:36
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* RC522 scan card and store card number */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Wire.h>
  25. #include <MFRC522.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF I2C PINS *****/
  32. const uint8_t Sceen_LCD1602I2C_I2C_PIN_SDA_D21 = 21;
  33. const uint8_t Sceen_LCD1602I2C_I2C_PIN_SCL_D22 = 22;
  34. const uint8_t Sceen_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  35.  
  36. // Create an instance of the MFRC522 library
  37. MFRC522 mfrc522(/*SS pin*/ 5, /*RST pin*/ 0); // Change SS and RST pins as needed
  38.  
  39. void setup(void)
  40. {
  41.   // put your setup code here, to run once:
  42.   Serial.begin(9600);
  43.   SPI.begin(); // Init SPI bus
  44.   mfrc522.PCD_Init(); // Init MFRC522 card
  45.  
  46.   Serial.println("Scan a RFID card");
  47. }
  48.  
  49. void loop(void)
  50. {
  51.   // put your main code here, to run repeatedly:
  52.   // Look for new cards
  53.   if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial())
  54.   {
  55.     Serial.println("A card is detected!");
  56.     // Print UID of the card
  57.     Serial.print("Card UID:");
  58.     for (byte i = 0; i < mfrc522.uid.size; i++)
  59.     {
  60.       Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  61.       Serial.print(mfrc522.uid.uidByte[i], HEX);
  62.     }
  63.     Serial.println();
  64.     mfrc522.PICC_HaltA(); // Halt PICC
  65.   }
  66. }
  67.  
  68. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement