Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <MFRC522.h>
- #include <Servo.h>
- #define SS_PIN 10
- #define RST_PIN 9
- #define servo_PIN 8
- String user1ID = "14 4A 6D 2B";
- String user2ID = "39 4B C8 B8";
- Servo myservo;
- MFRC522 mfrc522(SS_PIN, RST_PIN);
- void setup()
- {
- Serial.begin(9600); // Initiate a serial communication
- SPI.begin(); // Initiate SPI bus
- mfrc522.PCD_Init(); // Initiate MFRC522
- Serial.println("Approximate your card to the reader...");
- Serial.println();
- myservo.attach(servo_PIN);
- myservo.write(0);
- }
- void loop() {
- // Look for new cards
- if ( ! mfrc522.PICC_IsNewCardPresent())
- {
- return;
- }
- // Select one of the cards
- if ( ! mfrc522.PICC_ReadCardSerial())
- {
- return;
- }
- //Show UID on serial monitor
- Serial.println ("");
- Serial.println("UID tag :");
- String content = "";
- byte letter;
- for (byte i = 0; i < mfrc522.uid.size; i++)
- {
- content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
- content.concat(String(mfrc522.uid.uidByte[i], HEX));
- content.toUpperCase();
- }
- Serial.println(content.substring(1));
- if (content.substring(1) == user1ID || content.substring(1) == user2ID) {
- myservo.write(90);
- delay(2000);
- myservo.write(0);
- delay(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement