Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- All the resources for this project: https://www.hackster.io/Aritro
- Modified by Aritro Mukherjee
- */
- #include <SPI.h>
- #include <MFRC522.h>
- #include <SoftwareSerial.h>
- //SIM800L TX is connected to Arduino D7
- #define SIM800L_TX_PIN 7
- //SIM800L RX is connected to Arduino D6
- #define SIM800L_RX_PIN 6
- //Create software serial object to communicate with SIM800L
- SoftwareSerial serialSIM800L(SIM800L_TX_PIN, SIM800L_RX_PIN);
- #define SS_PIN 10
- #define RST_PIN 9
- MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
- void setup()
- {
- Serial.begin(9600); // Initiate a serial communication
- SPI.begin(); // Initiate SPI bus
- mfrc522.PCD_Init(); // Initiate MFRC522
- serialSIM800L.begin(9600);
- Serial.println("Setting up devices...");
- delay(10000);
- Serial.println("Setup Complete!");
- delay(3000);
- Serial.println("BAG Number");
- Serial.println();
- }
- 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.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) == "3C 7D 1E 2B") //change here the UID of the card/cards that you want to give access
- {
- Serial.println("Authorized access");
- Serial.println();
- delay(5000);
- sendSMSon1();
- delay(3000);
- }
- else if (content.substring(1) == "D6 17 FB 11")
- {
- Serial.println("Authorized access");
- Serial.println();
- delay(5000);
- sendSMSon2();
- delay(3000);
- }
- else {
- Serial.println(" Access denied");
- delay(3000);
- }
- }
- void sendSMSon1() {
- Serial.println("Sending Text...");
- serialSIM800L.print("AT+CMGF=1\r"); // Set the shield to SMS mode
- delay(100);
- serialSIM800L.print("AT+CMGS=\"0541394732\"\r");
- delay(200);
- serialSIM800L.print("UID tag : 3C 7D 1E 2B ");
- serialSIM800L.print("Bag #01");
- serialSIM800L.print("\r"); //the content of the message
- delay(500);
- serialSIM800L.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
- delay(100);
- serialSIM800L.println();
- Serial.println("Text Sent.");
- delay(500);
- }
- void sendSMSon2() {
- Serial.println("Sending Text...");
- serialSIM800L.print("AT+CMGF=1\r"); // Set the shield to SMS mode
- delay(100);
- serialSIM800L.print("AT+CMGS=\"0541394732\"\r");
- delay(200);
- serialSIM800L.print("UID tag : D6 17 FB 11 ");
- serialSIM800L.print("Bag #02");
- serialSIM800L.print("\r"); //the content of the message
- delay(500);
- serialSIM800L.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
- delay(100);
- serialSIM800L.println();
- Serial.println("Text Sent.");
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment