andretafta

Test RFID_LCD Blynk

Feb 17th, 2021 (edited)
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*PIN SDA/SS : D2
  2.  *PIN SCK : D5
  3.  *PIN MOSI: D7
  4.  *PIN MISO: D6
  5.  *PIN GND : GND
  6.  *PIN RST : D1
  7.  *PIN 3.3V: 3V
  8.  */
  9.  
  10. #define BLYNK_PRINT Serial
  11.  
  12. #include <SPI.h>
  13. #include <ESP8266WiFi.h>
  14. #include <BlynkSimpleEsp8266.h>
  15. #include <MFRC522.h>
  16.  
  17. #define SS_PIN D2
  18. #define RST_PIN D1
  19.  
  20. char auth[] = "Token Blynk";
  21. char ssid[] = "Nama Wifi";
  22. char pass[] = "Pass Wifi";
  23. char server[] = "blynk-cloud.com";
  24. int port = 8442;
  25.  
  26. MFRC522 rfid(SS_PIN, RST_PIN);
  27. MFRC522::MIFARE_Key key;
  28. WidgetLCD lcd(V1);    //Pin Virtual LCD di Blynk
  29.  
  30. String strID;
  31.  
  32. void setup()
  33. {
  34.   Serial.begin(115200);
  35.   Blynk.begin(auth, ssid, pass, server, port);
  36.   SPI.begin(); // Init SPI bus
  37.   rfid.PCD_Init(); // Init MFRC522
  38. }
  39.        
  40. void loop()      
  41. {
  42.   Blynk.run();
  43.   lcd.clear();
  44.   if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;
  45.   MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
  46.   if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
  47.       piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
  48.       piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
  49.     Serial.println(F("Your tag is not of type MIFARE Classic."));
  50.     return;
  51.   }
  52.   strID = "";
  53.   for (byte i = 0; i < 4; i++) {
  54.     strID +=
  55.       (rfid.uid.uidByte[i] < 0x10 ? "0" : "") +
  56.       String(rfid.uid.uidByte[i], HEX) +
  57.       (i != 3 ? ":" : "");
  58.   }
  59.   strID.toUpperCase();
  60.  
  61.   //Cetak di Serial Monitor apabila RFID Tag terdeteksi
  62.   if (strID != NULL)
  63.   {  
  64.     lcd.print(0, 0, "ID dari RFID :");                                              
  65.     lcd.print(0, 1, strID);
  66.     delay(2000);
  67.   }
  68.  
  69.   else{
  70.     lcd.print(0, 0, "ID dari RFID :");                                              
  71.     lcd.print(0, 1, "Tidak ditemukan");
  72.     delay(2000);
  73.   }
  74. }  
Add Comment
Please, Sign In to add comment