Advertisement
ocneves

leitor rfid

Feb 22nd, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. // --- Bibliotecas Auxiliares ---
  2. #include <SPI.h>
  3. #include <MFRC522.h>
  4.  
  5.  
  6. // --- Mapeamento de Hardware ---
  7. #define SS_PIN 8
  8.  
  9. #define RST_PIN 9
  10. MFRC522 mfrc522(SS_PIN, RST_PIN); // Cria instância com MFRC522
  11.  
  12. // --- Variáveis Globais ---
  13. char st[20];
  14.  
  15.  
  16. // --- Configurações Iniciais ---
  17. void setup()
  18. {
  19. Serial.begin(9600); // Inicia comunicação Serial em 9600 baud rate
  20. SPI.begin(); // Inicia comunicação SPI bus
  21. mfrc522.PCD_Init(); // Inicia MFRC522
  22.  
  23. //Serial.println("x");
  24. Serial.println();
  25.  
  26.  
  27. } //end setup
  28.  
  29.  
  30. // --- Loop Infinito ---
  31. void loop()
  32. {
  33. // Verifica novos cartões
  34. if ( ! mfrc522.PICC_IsNewCardPresent())
  35. {
  36. return;
  37. }
  38. // Seleciona um dos cartões
  39. if ( ! mfrc522.PICC_ReadCardSerial())
  40. {
  41. return;
  42. }
  43.  
  44. // Mostra UID na serial
  45. //Serial.print("UID da tag :");
  46. String conteudo= "";
  47. byte letra;
  48. for (byte i = 0; i < mfrc522.uid.size; i++)
  49. {
  50. //Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  51. //Serial.print(mfrc522.uid.uidByte[i], HEX);
  52. conteudo.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  53. conteudo.concat(String(mfrc522.uid.uidByte[i], HEX));
  54. }
  55. Serial.println();
  56. //Serial.print("Mensagem : ");
  57. conteudo.toUpperCase();
  58.  
  59. if (conteudo.substring(1) == "E3 F5 31 DB") //UID 1 - Chaveiro
  60. {
  61. Serial.println("boneca");
  62. Serial.println();
  63. delay(1000);
  64.  
  65. }
  66.  
  67. if (conteudo.substring(1) == "53 0A 6D D9") //UID 2 - Cartao
  68. {
  69. Serial.println("Bola");
  70. Serial.println();
  71. delay(1000);
  72.  
  73. }
  74.  
  75. if (conteudo.substring(1) == "F3 63 4C E5") //UID 2 - Cartao
  76. {
  77. Serial.println("carro");
  78. Serial.println();
  79. delay(1000);
  80.  
  81. }
  82.  
  83. } //end loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement