Advertisement
manvi_m

FINAL PROJECT

Jun 29th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. /*
  2. * Manvi Mittal
  3. * Final Project
  4. */
  5.  
  6. // variables for LEDS
  7. const int pinLedRed = 7;
  8. const int pinLedGreen = 6;
  9.  
  10. // variables for servo motor
  11. #include <Servo.h>
  12.  
  13. Servo miServito;
  14.  
  15.  
  16. // variables for piezo
  17. const int piezoPin = 8;
  18.  
  19. #include "pitches.h"
  20.  
  21. // notes in the melody:
  22. int melody[] = {
  23. NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
  24. };
  25.  
  26. // note durations: 4 = quarter note, 8 = eighth note, etc.:
  27. int noteDurations[] = {
  28. 4, 8, 8, 4, 4, 4, 4, 4
  29. };
  30.  
  31. // variables for RFID
  32. #include <SPI.h>
  33. #include <MFRC522.h>
  34.  
  35. #define RST_PIN 9 // Configurable, see typical pin layout above
  36. #define SS_PIN 10 // Configurable, see typical pin layout above
  37.  
  38. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
  39.  
  40. /* Set your new UID here! */
  41. #define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}
  42.  
  43. MFRC522::MIFARE_Key key;
  44.  
  45. // variables for LCD
  46. #include <LiquidCrystal.h>
  47.  
  48. LiquidCrystal lcd (15, 19, 16, 2, 4, 5);
  49.  
  50.  
  51. void setup() {
  52. // put your setup code here, to run once:
  53. // LED setup
  54. pinMode (pinLedRed, OUTPUT);
  55. pinMode (pinLedGreen, OUTPUT);
  56.  
  57. Serial.begin (9600);
  58.  
  59. // servo motor setup
  60. miServito.attach (3);
  61. Serial.begin (9600);
  62. miServito.write (140);
  63.  
  64. // piezo setup
  65. pinMode (piezoPin, OUTPUT);
  66. Serial.begin (9600);
  67.  
  68. // RFID setup
  69. Serial.begin(9600); // Initialize serial communications with the PC
  70. while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  71. SPI.begin(); // Init SPI bus
  72. mfrc522.PCD_Init(); // Init MFRC522 card
  73. Serial.println(F("Warning: this example overwrites the UID of your UID changeable card, use with care!"));
  74.  
  75. // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
  76. for (byte i = 0; i < 6; i++) {
  77. key.keyByte[i] = 0xFF;
  78. }
  79.  
  80. lcd.begin (16, 2);
  81.  
  82. }
  83.  
  84. void loop()
  85. {
  86. lcd.clear();
  87. delay (1);
  88. lcd.print ("SCAN KEY CARD");
  89. // Look for new cards
  90. if ( ! mfrc522.PICC_IsNewCardPresent())
  91. {
  92. return;
  93. }
  94. // Select one of the cards
  95. if ( ! mfrc522.PICC_ReadCardSerial())
  96. {
  97. return;
  98. }
  99. //Show UID on serial monitor
  100. Serial.print("UID tag :");
  101. String content= "";
  102. byte letter;
  103. for (byte i = 0; i < mfrc522.uid.size; i++)
  104. {
  105. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  106. Serial.print(mfrc522.uid.uidByte[i], HEX);
  107. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  108. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  109. }
  110. Serial.println();
  111. Serial.print("Message : ");
  112. content.toUpperCase();
  113. if (content.substring(1) == "3D 65 79 62") //change here the UID of the card/cards that you want to give access
  114. {
  115. Serial.println("Authorized access");
  116. Serial.println();
  117. delay(3000);
  118.  
  119. lcd.clear ();
  120. lcd.print("Welcome, Peter");
  121. delay(3000);
  122. lcd.clear ();
  123.  
  124. digitalWrite (pinLedGreen, HIGH);
  125. delay (1000);
  126. digitalWrite (pinLedGreen, LOW);
  127.  
  128. for (int thisNote = 0; thisNote < 8; thisNote++)
  129. {
  130.  
  131. int noteDuration = 1000 / noteDurations[thisNote];
  132. tone(8, melody[thisNote], noteDuration);
  133.  
  134. int pauseBetweenNotes = noteDuration * 1.30;
  135. delay(pauseBetweenNotes);
  136. // stop the tone playing:
  137. noTone(8);
  138. }
  139.  
  140. miServito.write (50);
  141. delay (5000);
  142. miServito.write (140);
  143.  
  144. }
  145. else if (content.substring(1) == "DC 10 C7 B2") //change here the UID of the card/cards that you want to give access
  146. {
  147. Serial.println("Authorized access");
  148. Serial.println();
  149. delay(3000);
  150.  
  151. lcd.clear ();
  152. lcd.print("Welcome, Paul");
  153. delay(3000);
  154. lcd.clear ();
  155.  
  156. digitalWrite (pinLedGreen, HIGH);
  157. delay (1000);
  158. digitalWrite (pinLedGreen, LOW);
  159.  
  160. for (int thisNote = 0; thisNote < 8; thisNote++)
  161. {
  162.  
  163. int noteDuration = 1000 / noteDurations[thisNote];
  164. tone(8, melody[thisNote], noteDuration);
  165.  
  166. int pauseBetweenNotes = noteDuration * 1.30;
  167. delay(pauseBetweenNotes);
  168. // stop the tone playing:
  169. noTone(8);
  170. }
  171.  
  172. miServito.write (50);
  173. delay (5000);
  174. miServito.write (140);
  175. }
  176.  
  177. else if (content.substring(1) == "22 99 00 0D") //change here the UID of the card/cards that you want to give access
  178. {
  179. Serial.println("Authorized access");
  180. Serial.println();
  181. delay(3000);
  182.  
  183. lcd.clear ();
  184. lcd.print("Welcome, Mary");
  185. delay(5000);
  186. lcd.clear ();
  187.  
  188. digitalWrite (pinLedGreen, HIGH);
  189. delay (1000);
  190. digitalWrite (pinLedGreen, LOW);
  191.  
  192. for (int thisNote = 0; thisNote < 8; thisNote++)
  193. {
  194.  
  195. int noteDuration = 1000 / noteDurations[thisNote];
  196. tone(8, melody[thisNote], noteDuration);
  197.  
  198. int pauseBetweenNotes = noteDuration * 1.30;
  199. delay(pauseBetweenNotes);
  200. // stop the tone playing:
  201. noTone(8);
  202. }
  203.  
  204. miServito.write (50);
  205. delay (5000);
  206. miServito.write (140);
  207. }
  208.  
  209. else {
  210. lcd.clear ();
  211. lcd.print("ACCESS DENIED");
  212. delay(3000);
  213. lcd.clear ();
  214.  
  215. digitalWrite (pinLedRed, HIGH);
  216. delay (1000);
  217. digitalWrite (pinLedRed, LOW);
  218.  
  219. tone (piezoPin, 100, 500);
  220. delay (500);
  221. noTone (piezoPin);
  222. }
  223.  
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement