My RFID Tag can’t get scanned when i use a Blynk Template code,
I use the template from this Youtube video :
“https://youtu.be/LqRDissHtys”
I have tried to scan the RFID Tag with a simple code just to see the ID, and it works.
But why can’t i scan the RFID Tag when i use the Blynk Template code ? Is there something wrong with the code ?
If there’s something wrong, how to fix it ? Please explain it step by step, I don’t really understand how to code, thank you for anyone who helps
• ESP8266 + WiFi
• Blynk server
• Blynk Library 1.2.0
This is the sketch code
#include <SPI.h>
#define BLYNK_TEMPLATE_ID "TMPL6BZv75tjv"
#define BLYNK_TEMPLATE_NAME "DoorLockFix2"
#define BLYNK_AUTH_TOKEN "ORpZeeVcfoZMfbDiETGwXketRj7Mno87"
#include <MFRC522.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define SS_PIN 4 // sda
#define RST_PIN 2
int lock = D1;
MFRC522 mfrc522(RST_PIN, SS_PIN); // Create MFRC522 instance.
char auth[] = BLYNK_AUTH_TOKEN; //Blynk Authentication Token -- sent via Email from Blynk
char ssid[] = "bb 6 no 1"; //Enter WiFi Name
char pass[] = "oliverap"; //Enter Wifi Password
SimpleTimer timer;
int fflag = 0;
int eflag = 0;
int jflag = 0;
WidgetTerminal terminal(V2);
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
Blynk.begin(auth, ssid, pass);
pinMode(lock,OUTPUT);
digitalWrite(lock, LOW);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
//Serial.println("Scan a MIFARE Classic PICC to demonstrate Value Blocks.");
timer.setInterval(1000L, iot_rfid);
}
void loop() {
timer.run(); // Initiates SimpleTimer
Blynk.run();
}
void iot_rfid()
{
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
MFRC522::MIFARE_Key key;
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Now a card is selected. The UID and SAK is in mfrc522.uid.
// Dump UID
Serial.print("Card UID:");
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], DEC);
}
Serial.println();
// Dump PICC type
byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
// Serial.print("PICC type: ");
//Serial.println(mfrc522.PICC_GetTypeName(piccType));
if ( piccType != MFRC522::PICC_TYPE_MIFARE_MINI
&& piccType != MFRC522::PICC_TYPE_MIFARE_1K
&& piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
//Serial.println("This sample only works with MIFARE Classic cards.");
return;
}
// Enter RFID Tag ID here
if( ((mfrc522.uid.uidByte[0] == 11) && (mfrc522.uid.uidByte[1] == 22) && (mfrc522.uid.uidByte[2] == 33) && (mfrc522.uid.uidByte[3] == 44)) && (fflag == 1) )
{
Serial.println("User01"); //Enter User1 Name
Blynk.virtualWrite(V2, "User01" ); //Enter User1 Name
digitalWrite(lock, HIGH);
delay(3000);
digitalWrite(lock, LOW);
}
else
if(( (mfrc522.uid.uidByte[0] == 11) && (mfrc522.uid.uidByte[1] == 12) && (mfrc522.uid.uidByte[2] == 13) && (mfrc522.uid.uidByte[3] == 14))&& (eflag == 1) )
{
Serial.println("User02"); //Enter User2 Name
Blynk.virtualWrite(V2, "User02" ); //Enter User2 Name
digitalWrite(lock, HIGH);
delay(3000);
digitalWrite(lock, LOW);
}
else
if( ((mfrc522.uid.uidByte[0] == 21) && (mfrc522.uid.uidByte[1] == 22) && (mfrc522.uid.uidByte[2] == 23) && (mfrc522.uid.uidByte[3] == 24))&& (jflag == 1) )
{
Serial.println("User03"); //Enter User3 Name
Blynk.virtualWrite(V2, "User03" ); //Enter User3 Name
digitalWrite(lock, HIGH);
delay(3000);
digitalWrite(lock, LOW);
}
else
Serial.println("Unregistered User");
}
// in Blynk app writes values to the Virtual Pin 3
BLYNK_WRITE(V3)
{
fflag = param.asInt(); // assigning incoming value from pin V3 to a variable
// Blynk.virtualWrite(V2, fflag );
}
// in Blynk app writes values to the Virtual Pin 4
BLYNK_WRITE(V4)
{
eflag = param.asInt(); // assigning incoming value from pin V4 to a variable
}
BLYNK_WRITE(V5)
{
jflag = param.asInt(); // assigning incoming value from pin V5 to a variable
}