safwan092

Project - 7381 - Code Only

Feb 3rd, 2021
895
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2. #include <MFRC522.h>
  3. #include <Servo.h>
  4.  
  5. #define SS_PIN 10
  6. #define RST_PIN 9
  7. #define LED_B 6
  8. #define BUZZER 7
  9. MFRC522 mfrc522(SS_PIN, RST_PIN);
  10. Servo myServo;
  11.  
  12. void setup()
  13. {
  14.   Serial.begin(9600);
  15.   SPI.begin();
  16.   mfrc522.PCD_Init();
  17.   myServo.attach(5);
  18.   myServo.write(10);
  19.   pinMode(LED_B, OUTPUT);
  20.   pinMode(BUZZER, OUTPUT);
  21.   digitalWrite(BUZZER,1);
  22.   digitalWrite(LED_B,1);
  23.   Serial.println("Scanning Card...");
  24.   Serial.println();
  25.  
  26. }
  27. void loop()
  28. {
  29.   // Look for new cards
  30.   if ( ! mfrc522.PICC_IsNewCardPresent())
  31.   {
  32.     return;
  33.   }
  34.   // Select one of the cards
  35.   if ( ! mfrc522.PICC_ReadCardSerial())
  36.   {
  37.     return;
  38.   }
  39.   //Show UID on serial monitor
  40.   Serial.print("UID tag :");
  41.   String content= "";
  42.   byte letter;
  43.   for (byte i = 0; i < mfrc522.uid.size; i++)
  44.   {
  45.      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  46.      Serial.print(mfrc522.uid.uidByte[i], HEX);
  47.      content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  48.      content.concat(String(mfrc522.uid.uidByte[i], HEX));
  49.   }
  50.   Serial.println();
  51.   Serial.print("State : ");
  52.   content.toUpperCase();
  53.   if (content.substring(1) == "59 55 E4 D5" || content.substring(1) == "A9 81 68 B2")
  54.   {
  55.     Serial.println("OK");
  56.     delay(500);
  57.     digitalWrite(LED_B, 0);
  58.     digitalWrite(BUZZER,0);
  59.     delay(100);
  60.     digitalWrite(BUZZER,1);
  61.     myServo.write(100);
  62.     delay(5000);
  63.     myServo.write(10);
  64.     digitalWrite(LED_B, 1);
  65.   }
  66.  
  67.  else   {
  68.     Serial.println("n/a");
  69.     digitalWrite(BUZZER,0);
  70.     delay(100);
  71.     digitalWrite(BUZZER,1);
  72.     delay(500);
  73.   }
  74. }
RAW Paste Data