Advertisement
Guest User

Untitled

a guest
Sep 10th, 2017
140
0
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. #include <Stepper.h>
  5. #include <IRremote.h>
  6. int SPU = 2048;
  7. int RECV_PIN = 2;
  8.  
  9.  
  10. #define SS_PIN 10 // RFID-RC522 SDA
  11. #define RST_PIN 9 // RFID-RC522 RST
  12.  
  13. const byte servoPin = 8; // digital Pin - Servo
  14. const byte buzzerPin = 7; // digital Pin - Buzzer
  15.  
  16. Servo myServo;
  17. MFRC522 mfrc522(SS_PIN, RST_PIN);
  18. Stepper Motor(SPU, 3,5,4,6);
  19. IRrecv irrecv(RECV_PIN);
  20.  
  21. // Hier die UUID fuer erlaubte Karten eingeben und in "erlaubteKartenCount"
  22. // Anzahl der Eintraege angeben
  23. long erlaubteKarten[] = { 2131040, 2541780 ,1924170 };
  24. byte erlaubteKartenCount = 3;
  25. decode_results results;
  26.  
  27. boolean PruefeKartenberechtigung(long KartenUUID) {
  28. boolean erlaubt = false;
  29.  
  30. for(int i=0; i < erlaubteKartenCount; i++) {
  31. if(erlaubteKarten[i] == KartenUUID) {
  32. erlaubt = true;
  33. }
  34. }
  35. return erlaubt;
  36. }
  37.  
  38.  
  39.  
  40.  
  41. void UnbekannteKarteSound(void) {
  42. for (byte i=0; i<3; i++) {
  43. tone(buzzerPin, 500, 150);
  44. delay(200);
  45. }
  46. }
  47.  
  48.  
  49.  
  50. void KarteErkanntSound(void) {
  51. tone(buzzerPin, 1000, 150);
  52. delay(200);
  53. tone(buzzerPin, 1500, 150);
  54. delay(200);
  55. }
  56.  
  57.  
  58. void setup() {
  59. Serial.begin(9600);
  60. SPI.begin();
  61. mfrc522.PCD_Init();
  62. Motor.setSpeed(5);
  63.  
  64. pinMode (13, OUTPUT);
  65. pinMode(buzzerPin, OUTPUT);
  66. pinMode(servoPin, OUTPUT);
  67. digitalWrite(13, LOW);
  68. irrecv.enableIRIn();
  69.  
  70. myServo.attach(servoPin);
  71. myServo.write(0); //Servo auf Grundstellung
  72. }
  73.  
  74.  
  75.  
  76. void loop() {
  77. if (irrecv.decode(&results)) {
  78.  
  79. Serial.println(results.value, DEC);
  80.  
  81. if (results.value == 16724175)
  82.  
  83.  
  84. {digitalWrite (13, HIGH);}
  85.  
  86. if (results.value == 16718055)
  87.  
  88. {digitalWrite (13, LOW);}
  89.  
  90. irrecv.resume();
  91. if ( ! mfrc522.PICC_IsNewCardPresent()) {
  92. return;
  93. }
  94.  
  95. if ( ! mfrc522.PICC_ReadCardSerial()) {
  96. return;
  97. }
  98.  
  99. long code=0;
  100.  
  101. for (byte i = 0; i < mfrc522.uid.size; i++) {
  102. code=((code+mfrc522.uid.uidByte[i])*10);
  103. }
  104.  
  105. Serial.print(F("Erkannte Kartennummer:"));
  106. Serial.print(code);
  107.  
  108. if(PruefeKartenberechtigung(code) == true) {
  109. Serial.println(F(" [BERECHTIGT]"));
  110. KarteErkanntSound();
  111. Motor.step(1224);
  112. delay(8000);
  113. Motor.step(1224);
  114. delay(8000);
  115. myServo.write(90);
  116. delay(8000);
  117. myServo.write(0);
  118. delay(8000);
  119. } else {
  120. Serial.println(F(" [NICHT BERECHTIGT]"));
  121. UnbekannteKarteSound();
  122. }
  123. delay(2000);
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement