safwan092

Untitled

Dec 15th, 2020
836
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2. #include <MFRC522.h>
  3.  
  4. String card[2] = {
  5.   "A0 EA 57 32" // ---> Valid
  6.   ,
  7.   "A9 C0 15 BA" // ---> Valid
  8. };
  9. const int microwavePin = 4;
  10. const int buzzerPin = 8;
  11. const int ledPin = 7;
  12.  
  13. String a = "";
  14. MFRC522 mfrc522(10, 9);
  15.  
  16. int count = 0;
  17. bool seats[2] = {0};
  18. int out = 0;
  19.  
  20. void setup() {
  21.   Serial.begin(115200);   // Initiate a serial communication
  22.   pinMode(6, OUTPUT);
  23.   digitalWrite(6, 1);
  24.   pinMode(buzzerPin, OUTPUT);
  25.   pinMode(microwavePin, INPUT);
  26.   pinMode(ledPin, OUTPUT);
  27.   SPI.begin();      // Initiate  SPI bus
  28.   mfrc522.PCD_Init();   // Initiate MFRC522
  29.   Serial.print("starting");
  30. }
  31.  
  32. void loop() {
  33.   // Look for new cards
  34.   if ( ! mfrc522.PICC_IsNewCardPresent())
  35.   {
  36.     return;
  37.   }
  38.   // Select one of the cards
  39.   if ( ! mfrc522.PICC_ReadCardSerial())
  40.   {
  41.     return;
  42.   }
  43.   String content = "";
  44.   byte letter;
  45.   for (byte i = 0; i < mfrc522.uid.size; i++)
  46.   {
  47.     // To show cards UUID, un-comment the next line
  48.     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  49.     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  50.   }
  51.   content.toUpperCase();
  52.  
  53.   Serial.println(content.substring(1));
  54.   for (int j = 0; j < 2; j++) {
  55.     if (content.substring(1) == card[j]) //change UID of the card that you want to give access
  56.     {
  57.  
  58.       buzz();
  59.       delay(1000);
  60.       while (1) {
  61.         int microwave = digitalRead(microwavePin);
  62.         if (microwave == 1) {
  63.           digitalWrite(ledPin, HIGH);
  64.           Serial.println(microwave);
  65.           //buzz();
  66.         }
  67.         else {
  68.  
  69.           digitalWrite(ledPin, LOW);
  70.           digitalWrite(6, 0);
  71.           Serial.println(microwave);
  72.           break;
  73.         }
  74.       }
  75.     }
  76.   }
  77. }// end of loop
  78.  
  79.  
  80. void buzz() {
  81.   digitalWrite(buzzerPin, 1);
  82.   delay(100);
  83.   digitalWrite(buzzerPin, 0);
  84.   delay(50);
  85. }
RAW Paste Data