jacknpoe

leitor RFID

Dec 8th, 2025 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.13 KB | Software | 0 0
  1. #include <SPI.h>            
  2. #include <MFRC522.h>
  3. #include <LiquidCrystal_I2C.h>
  4.  
  5. #define PINO_SS 10
  6. #define PINO_RST 9
  7.  
  8. MFRC522 leitor( PINO_SS, PINO_RST);  // leitor RFID
  9. LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);  // objeto do Cristal Líquido 16x2 I2C
  10.  
  11. void setup() {
  12.   SPI.begin();  // inicia comunicação SPI bus, eu não tenho a menor ideia do que isso faz, mas está nos exemplos sem explicação
  13.   leitor.PCD_Init();  // inicia o leitor
  14.   LCD.init();  // inicia o Cristal Líquido
  15.   LCD.backlight();  //liga a luz de fundo
  16. }
  17.  
  18. void loop() {
  19.   String cartao = "";
  20.   if( leitor.PICC_IsNewCardPresent())  // se um novo cartão foi apresentado
  21.   {
  22.     if( leitor.PICC_ReadCardSerial())  // lê o serial do cartão
  23.     {
  24.       for(int indice = 0; indice < leitor.uid.size; indice++)  // acumula os hexadecimais do cartão em "cartao"
  25.         cartao = cartao + ( leitor.uid.uidByte[indice] < 0x10 ? "0" : "") + String( leitor.uid.uidByte[indice], HEX);
  26.  
  27.       LCD.clear();
  28.       LCD.setCursor(0, 0);
  29.       LCD.print( "UID:");
  30.       LCD.setCursor(0, 1);
  31.       LCD.print( cartao);
  32.  
  33.       delay( 1000);
  34.     }
  35.   }
  36. }
Tags: RFID
Advertisement
Add Comment
Please, Sign In to add comment