Advertisement
pleasedontcode

RFID Scanner rev_03

May 9th, 2024
1,045
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 compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-05-09 11:03:51
  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.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Wire.h>
  26. #include <MFRC522.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF I2C PINS *****/
  33. const uint8_t Sceen_LCD1602I2C_I2C_PIN_SDA_D21 = 21;
  34. const uint8_t Sceen_LCD1602I2C_I2C_PIN_SCL_D22 = 22;
  35. const uint8_t Sceen_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  36.  
  37. // Create an instance of the MFRC522 library
  38. MFRC522 mfrc522(/*SS pin*/ 5, /*RST pin*/ 0); // Change SS and RST pins as needed
  39.  
  40. void setup(void)
  41. {
  42.   // put your setup code here, to run once:
  43.   Serial.begin(9600);
  44.   SPI.begin(); // Init SPI bus
  45.   mfrc522.PCD_Init(); // Init MFRC522 card
  46.  
  47.   Serial.println("Scan a RFID card");
  48. }
  49.  
  50. void loop(void)
  51. {
  52.   // put your main code here, to run repeatedly:
  53.   // Look for new cards
  54.   if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial())
  55.   {
  56.     Serial.println("A card is detected!");
  57.     // Print UID of the card
  58.     Serial.print("Card UID:");
  59.     for (byte i = 0; i < mfrc522.uid.size; i++)
  60.     {
  61.       Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  62.       Serial.print(mfrc522.uid.uidByte[i], HEX);
  63.     }
  64.     Serial.println();
  65.     mfrc522.PICC_HaltA(); // Halt PICC
  66.   }
  67. }
  68.  
  69. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement