Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Manvi Mittal
- * Final Project
- */
- // variables for LEDS
- const int pinLedRed = 7;
- const int pinLedGreen = 6;
- // variables for servo motor
- #include <Servo.h>
- Servo miServito;
- // variables for piezo
- const int piezoPin = 8;
- #include "pitches.h"
- // notes in the melody:
- int melody[] = {
- NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
- };
- // note durations: 4 = quarter note, 8 = eighth note, etc.:
- int noteDurations[] = {
- 4, 8, 8, 4, 4, 4, 4, 4
- };
- // variables for RFID
- #include <SPI.h>
- #include <MFRC522.h>
- #define RST_PIN 9 // Configurable, see typical pin layout above
- #define SS_PIN 10 // Configurable, see typical pin layout above
- MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
- /* Set your new UID here! */
- #define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}
- MFRC522::MIFARE_Key key;
- // variables for LCD
- #include <LiquidCrystal.h>
- LiquidCrystal lcd (15, 19, 16, 2, 4, 5);
- void setup() {
- // put your setup code here, to run once:
- // LED setup
- pinMode (pinLedRed, OUTPUT);
- pinMode (pinLedGreen, OUTPUT);
- Serial.begin (9600);
- // servo motor setup
- miServito.attach (3);
- Serial.begin (9600);
- miServito.write (140);
- // piezo setup
- pinMode (piezoPin, OUTPUT);
- Serial.begin (9600);
- // RFID setup
- Serial.begin(9600); // Initialize serial communications with the PC
- while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
- SPI.begin(); // Init SPI bus
- mfrc522.PCD_Init(); // Init MFRC522 card
- Serial.println(F("Warning: this example overwrites the UID of your UID changeable card, use with care!"));
- // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
- for (byte i = 0; i < 6; i++) {
- key.keyByte[i] = 0xFF;
- }
- lcd.begin (16, 2);
- }
- void loop()
- {
- lcd.clear();
- delay (1);
- lcd.print ("SCAN KEY CARD");
- // 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.print("UID tag :");
- 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();
- Serial.print("Message : ");
- content.toUpperCase();
- if (content.substring(1) == "3D 65 79 62") //change here the UID of the card/cards that you want to give access
- {
- Serial.println("Authorized access");
- Serial.println();
- delay(3000);
- lcd.clear ();
- lcd.print("Welcome, Peter");
- delay(3000);
- lcd.clear ();
- digitalWrite (pinLedGreen, HIGH);
- delay (1000);
- digitalWrite (pinLedGreen, LOW);
- for (int thisNote = 0; thisNote < 8; thisNote++)
- {
- int noteDuration = 1000 / noteDurations[thisNote];
- tone(8, melody[thisNote], noteDuration);
- int pauseBetweenNotes = noteDuration * 1.30;
- delay(pauseBetweenNotes);
- // stop the tone playing:
- noTone(8);
- }
- miServito.write (50);
- delay (5000);
- miServito.write (140);
- }
- else if (content.substring(1) == "DC 10 C7 B2") //change here the UID of the card/cards that you want to give access
- {
- Serial.println("Authorized access");
- Serial.println();
- delay(3000);
- lcd.clear ();
- lcd.print("Welcome, Paul");
- delay(3000);
- lcd.clear ();
- digitalWrite (pinLedGreen, HIGH);
- delay (1000);
- digitalWrite (pinLedGreen, LOW);
- for (int thisNote = 0; thisNote < 8; thisNote++)
- {
- int noteDuration = 1000 / noteDurations[thisNote];
- tone(8, melody[thisNote], noteDuration);
- int pauseBetweenNotes = noteDuration * 1.30;
- delay(pauseBetweenNotes);
- // stop the tone playing:
- noTone(8);
- }
- miServito.write (50);
- delay (5000);
- miServito.write (140);
- }
- else if (content.substring(1) == "22 99 00 0D") //change here the UID of the card/cards that you want to give access
- {
- Serial.println("Authorized access");
- Serial.println();
- delay(3000);
- lcd.clear ();
- lcd.print("Welcome, Mary");
- delay(5000);
- lcd.clear ();
- digitalWrite (pinLedGreen, HIGH);
- delay (1000);
- digitalWrite (pinLedGreen, LOW);
- for (int thisNote = 0; thisNote < 8; thisNote++)
- {
- int noteDuration = 1000 / noteDurations[thisNote];
- tone(8, melody[thisNote], noteDuration);
- int pauseBetweenNotes = noteDuration * 1.30;
- delay(pauseBetweenNotes);
- // stop the tone playing:
- noTone(8);
- }
- miServito.write (50);
- delay (5000);
- miServito.write (140);
- }
- else {
- lcd.clear ();
- lcd.print("ACCESS DENIED");
- delay(3000);
- lcd.clear ();
- digitalWrite (pinLedRed, HIGH);
- delay (1000);
- digitalWrite (pinLedRed, LOW);
- tone (piezoPin, 100, 500);
- delay (500);
- noTone (piezoPin);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement