safwan092

Bag Tracking Using RFID + GSM (SIM800L)

Apr 7th, 2018
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.22 KB | None | 0 0
  1. /*
  2.  
  3.    All the resources for this project: https://www.hackster.io/Aritro
  4.    Modified by Aritro Mukherjee
  5.  
  6.  
  7. */
  8.  
  9. #include <SPI.h>
  10. #include <MFRC522.h>
  11. #include <SoftwareSerial.h>
  12.  
  13. //SIM800L TX is connected to Arduino D7
  14. #define SIM800L_TX_PIN 7
  15.  
  16. //SIM800L RX is connected to Arduino D6
  17. #define SIM800L_RX_PIN 6
  18.  
  19. //Create software serial object to communicate with SIM800L
  20. SoftwareSerial serialSIM800L(SIM800L_TX_PIN, SIM800L_RX_PIN);
  21.  
  22.  
  23.  
  24. #define SS_PIN 10
  25. #define RST_PIN 9
  26.  
  27.  
  28.  
  29. MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
  30.  
  31. void setup()
  32. {
  33.   Serial.begin(9600);   // Initiate a serial communication
  34.   SPI.begin();      // Initiate  SPI bus
  35.  
  36.   mfrc522.PCD_Init();   // Initiate MFRC522
  37.  
  38.   serialSIM800L.begin(9600);
  39.   Serial.println("Setting up devices...");
  40.   delay(10000);
  41.   Serial.println("Setup Complete!");
  42.   delay(3000);
  43.   Serial.println("BAG Number");
  44.   Serial.println();
  45.  
  46.  
  47. }
  48. void loop()
  49. {
  50.   // Look for new cards
  51.   if ( ! mfrc522.PICC_IsNewCardPresent())
  52.   {
  53.     return;
  54.   }
  55.   // Select one of the cards
  56.   if ( ! mfrc522.PICC_ReadCardSerial())
  57.   {
  58.     return;
  59.   }
  60.   //Show UID on serial monitor
  61.   Serial.print("UID tag :");
  62.   String content = "";
  63.   byte letter;
  64.   for (byte i = 0; i < mfrc522.uid.size; i++)
  65.   {
  66.     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
  67.     Serial.print(mfrc522.uid.uidByte[i], HEX);
  68.     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  69.     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  70.   }
  71.   Serial.println();
  72.   Serial.print("Message : ");
  73.   content.toUpperCase();
  74.   if (content.substring(1) == "3C 7D 1E 2B") //change here the UID of the card/cards that you want to give access
  75.  
  76.   {
  77.     Serial.println("Authorized access");
  78.     Serial.println();
  79.     delay(5000);
  80.     sendSMSon1();
  81.     delay(3000);
  82.  
  83.   }
  84.  
  85.   else if (content.substring(1) == "D6 17 FB 11")
  86.   {
  87.     Serial.println("Authorized access");
  88.     Serial.println();
  89.     delay(5000);
  90.     sendSMSon2();
  91.     delay(3000);
  92.  
  93.   }
  94.   else   {
  95.     Serial.println(" Access denied");
  96.     delay(3000);
  97.   }
  98. }
  99.  
  100.  
  101.  
  102. void sendSMSon1() {
  103.  
  104.   Serial.println("Sending Text...");
  105.   serialSIM800L.print("AT+CMGF=1\r"); // Set the shield to SMS mode
  106.   delay(100);
  107.   serialSIM800L.print("AT+CMGS=\"0541394732\"\r");
  108.   delay(200);
  109.   serialSIM800L.print("UID tag :  3C 7D 1E 2B ");
  110.   serialSIM800L.print("Bag #01");
  111.   serialSIM800L.print("\r"); //the content of the message
  112.   delay(500);
  113.   serialSIM800L.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
  114.   delay(100);
  115.   serialSIM800L.println();
  116.   Serial.println("Text Sent.");
  117.   delay(500);
  118.  
  119. }
  120.  
  121. void sendSMSon2() {
  122.  
  123.   Serial.println("Sending Text...");
  124.   serialSIM800L.print("AT+CMGF=1\r"); // Set the shield to SMS mode
  125.   delay(100);
  126.   serialSIM800L.print("AT+CMGS=\"0541394732\"\r");
  127.   delay(200);
  128.   serialSIM800L.print("UID tag :  D6 17 FB 11 ");
  129.   serialSIM800L.print("Bag #02");
  130.   serialSIM800L.print("\r"); //the content of the message
  131.   delay(500);
  132.   serialSIM800L.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
  133.   delay(100);
  134.   serialSIM800L.println();
  135.   Serial.println("Text Sent.");
  136.   delay(500);
  137.  
  138. }
Advertisement
Add Comment
Please, Sign In to add comment