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
- Servo servo1;
- Servo servo2;
- Servo servo3;
- Servo servo4;
- MFRC522 mfrc522(SS_PIN, RST_PIN);
- void setup() {
- servo1.attach(2);
- servo2.attach(3);
- servo3.attach(4);
- servo4.attach(5);
- servo1.write(0);
- servo2.write(0);
- servo3.write(0);
- servo4.write(0);
- Serial.begin(9600);
- SPI.begin();
- mfrc522.PCD_Init();
- delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
- mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
- Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
- Serial.println("Starting...");
- Serial.println(F("Scan a Card"));
- }
- void loop() {
- //Serial.println("welcome to the loop");
- if ( ! mfrc522.PICC_IsNewCardPresent()) {
- return;
- }
- if ( ! mfrc522.PICC_ReadCardSerial() ) {
- return;
- }
- String content = "";
- byte letter;
- for (byte i = 0; i < mfrc522.uid.size; i++) {
- Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
- Serial.print(mfrc522.uid.uidByte[i], HEX);
- content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
- content.concat(String(mfrc522.uid.uidByte[i], HEX));
- }
- Serial.println();
- content.toUpperCase();
- //Tag #1 ID : 53 2A 52 B2 50 00 01
- //Tag #2 ID : 53 29 52 B2 50 00 01
- //Tag #3 ID : 53 28 52 B2 50 00 01
- //Tag #4 ID : 53 23 52 B2 50 00 01
- if (content.substring(1) == "53 2A 52 B2 50 00 01") {
- TagNo1Function();
- }
- else if (content.substring(1) == "53 29 52 B2 50 00 01") {
- TagNo2Function();
- }
- else if (content.substring(1) == "53 28 52 B2 50 00 01") {
- TagNo3Function();
- }
- else if (content.substring(1) == "53 23 52 B2 50 00 01") {
- TagNo4Function();
- }
- }
- void TagNo1Function() {
- servo1.write(90);
- delay(3000);
- servo1.write(0);
- }
- void TagNo2Function() {
- servo2.write(90);
- delay(3000);
- servo2.write(0);
- }
- void TagNo3Function() {
- servo3.write(90);
- delay(3000);
- servo3.write(0);
- }
- void TagNo4Function() {
- servo4.write(90);
- delay(3000);
- servo4.write(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment