Advertisement
ocneves

rfid_multi_tag_leitor

Mar 1st, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. // O sistema faz a luz apagar e envia uma mensagem para o serial quando o tag é afastado.
  2. // Agradecimentos a Nelson Toshio Hirai e Rhaicmer Braulio da Costa do Labdegaragem
  3. #include <SPI.h>
  4. #include <MFRC522.h>
  5.  
  6. #define SS_PIN1 8
  7. #define SS_PIN2 10
  8. #define RST_PIN 9
  9. MFRC522 mfrc522_1(SS_PIN1, RST_PIN); // Create MFRC522_2 instance.
  10. MFRC522 mfrc522_2(SS_PIN2, RST_PIN); // Cria MFRC522 instance.
  11. int ledpin7 = 7;
  12. int ledpin5 = 5;
  13. char st[20];
  14. byte State = 0;
  15.  
  16. void setup()
  17. {
  18. Serial.begin(9600);
  19. SPI.begin(); // Inicia SPI bus
  20. mfrc522_1.PCD_Init(); // Inicia MFRC522_1
  21. mfrc522_2.PCD_Init(); // Inicia MFRC522_2
  22. pinMode (ledpin7 , OUTPUT);
  23. pinMode (ledpin5 , OUTPUT);
  24. }
  25. void loop()
  26. {
  27. Tag1();
  28. Tag2();
  29. }
  30. void Tag1()
  31. {
  32. // Se o ledpin7 estiver acesso envia print "y"
  33. if( digitalRead(ledpin5) == HIGH )
  34. { Serial.println("y");
  35. delay(2000);}
  36.  
  37.  
  38. // Select one of the cards
  39.  
  40. if ( ! mfrc522_1.PICC_ReadCardSerial())
  41.  
  42. // Look for new cards
  43. if ( ! mfrc522_1.PICC_IsNewCardPresent())
  44. { //Acende o ledpin5
  45. digitalWrite (ledpin5 , HIGH);
  46. return ;
  47.  
  48. }
  49.  
  50. //Serial.print("UID da tag :");
  51. String conteudo= "";
  52. byte letra;
  53. for (byte i = 0; i < mfrc522_1.uid.size; i++)
  54. {
  55. //Serial.print(mfrc522_1.uid.uidByte[i] < 0x10 ? " 0" : " ");
  56. //Serial.print(mfrc522_1.uid.uidByte[i], HEX);
  57. conteudo.concat(String(mfrc522_1.uid.uidByte[i] < 0x10 ? " 0" : " "));
  58. conteudo.concat(String(mfrc522_1.uid.uidByte[i], HEX));
  59. }
  60. conteudo.toUpperCase();
  61. if (conteudo.substring(1) == "E3 F5 31 DB") //UID 1 - Chaveiro
  62. {
  63. digitalWrite (ledpin5 , LOW);
  64. //Serial.println("standby");
  65. }
  66.  
  67. delay(500);
  68. }
  69.  
  70. void Tag2()
  71. {
  72. // Se o ledpin7 estiver acesso envia print "K"
  73. if( digitalRead(ledpin7) == HIGH )
  74. { Serial.println("k");
  75. delay(2000);}
  76.  
  77.  
  78. // Select one of the cards
  79.  
  80. if ( ! mfrc522_2.PICC_ReadCardSerial())
  81.  
  82. // Look for new cards
  83. if ( ! mfrc522_2.PICC_IsNewCardPresent())
  84. { //Acende o ledpin7
  85. digitalWrite (ledpin7 , HIGH);
  86. return ;
  87.  
  88. }
  89.  
  90. //Serial.print("UID da tag :");
  91. String conteudo= "";
  92. byte letra;
  93. for (byte i = 0; i < mfrc522_2.uid.size; i++)
  94. {
  95. //Serial.print(mfrc522_2.uid.uidByte[i] < 0x10 ? " 0" : " ");
  96. //Serial.print(mfrc522_2.uid.uidByte[i], HEX);
  97. conteudo.concat(String(mfrc522_2.uid.uidByte[i] < 0x10 ? " 0" : " "));
  98. conteudo.concat(String(mfrc522_2.uid.uidByte[i], HEX));
  99. }
  100. conteudo.toUpperCase();
  101. if (conteudo.substring(1) == "53 0A 6D D9") //UID 1 - Chaveiro
  102. {
  103. digitalWrite (ledpin7 , LOW);
  104. //Serial.println("standby");
  105. }
  106.  
  107. delay(500);
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement