Arduino Blynk RFID and Bridge Widget

HI,
I’m trying to use this sketch

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <RFID.h>
#define SS_PIN 10
#define RST_PIN 9
#define led 3

RFID rfid(SS_PIN,RST_PIN);

int power = 8; 
int serNum[5];
int cards[][5] = {{109,2,10,187,222},{181,156,170,67,192},{37,116,216,101,236}};
bool access = false;


char auth[] = "473457fa470c42edb5c6c340661e2019";

WidgetBridge bridge1(V1);

// Timer for blynking
BlynkTimer timer;

static bool value = true;



BLYNK_CONNECTED() {
  bridge1.setAuthToken("545db7988e09468da8bae2506b99bc25"); // Place the AuthToken of the second hardware here
}

 void setup()
{
  // Debug console
 Serial.begin(9600);

 Blynk.begin(auth);
SPI.begin();
rfid.init();
pinMode(led, OUTPUT);
digitalWrite(led, LOW);

timer.setInterval(1000L, readRfid);
}


void readRfid()
{

           if(rfid.isCard()){

            if(rfid.readCardSerial()){
             Serial.print(rfid.serNum[0]);
        Serial.print(" ");
        Serial.print(rfid.serNum[1]);
        Serial.print(" ");
        Serial.print(rfid.serNum[2]);
        Serial.print(" ");
        Serial.print(rfid.serNum[3]);
        Serial.print(" ");
        Serial.print(rfid.serNum[4]);
        Serial.println("");
        
        for(int x = 0; x < sizeof(cards); x++){
          for(int i = 0; i < sizeof(rfid.serNum); i++ ){
              if(rfid.serNum[i] != cards[x][i]) {
                  access = false;
                  break;
              } else {
                  access = true;
              }
          }
          if(access) break;
        }
       
    }
    
   if(access){
      Serial.println("Welcome!");
      bridge1.digitalWrite(3, LOW);
      digitalWrite(led, HIGH);
      delay(1000);
      bridge1.digitalWrite(3, HIGH);
      digitalWrite(led, LOW);
      delay(1000);
       
       
  } else {
       Serial.println("Not allowed!"); 
       digitalWrite(led, HIGH);
       delay(500);
       digitalWrite(led, LOW); 
       delay(500);
       digitalWrite(led, HIGH);
       delay(500);
       digitalWrite(led, LOW);         
   }        
}



rfid.halt();

}


void loop()
{
  Blynk.run();
  timer.run();
}

but it doesn’t work… blynk says it is offline, but all network lights is blinking

change all your delay()'s to say 50 rather than 1000 and 500.

You can’t have 1000 when the function is to be repeated every 1s and delay() is VERY bad practise.

if(access){
      Serial.println("Welcome!");
      bridge1.digitalWrite(3, LOW);
      digitalWrite(led, HIGH);
      delay(50);
      bridge1.digitalWrite(3, HIGH);
      digitalWrite(led, LOW);
      delay(50);
       
       
  } else {
       Serial.println("Not allowed!"); 
       digitalWrite(led, HIGH);
       delay(50);
       digitalWrite(led, LOW); 
       delay(50);
       digitalWrite(led, HIGH);
       delay(50);
       digitalWrite(led, LOW);         
   }        
}

Like this??

Yes that is better but as you progress you will learn to stop using delay() altogether.

i tried and it keeps offline when i connect to app… :confused:

Hi, anyone here has a project made with RFID? Can you share with me? I want to use RFID, but I tried almost everything and it doesn’t work…

This is all the same forum and people :wink: So please don’t create multiple topics on the same subject… I moved your post back into this topic.

1 Like

@Fabio_Faria did you get the RFID working without Blynk as this is always the first step?

Yes, without blynk it work perfectely

Add this as your first line and then paste your Serial Monitor data:

#define BLYNK_DEBUG

You might need to go with an interrupt routine to ensure the RFID is ready before you swipe the card but this could be done with a simple LED routine.

I have RFID sketches for Blynk but teaching you how to fish is much better than giving you a few fish.

Nothing… Tried to connect with PC Ethernet cable, and get error DHCP (301)… I think i’ll give up

it only work on the ouside ethernet cable, and if i use RFID code it goes offline forever…

Hey, Did you get it to work?

@diego.bonagurio11 This is a very old topic and the OP hasn’t been seen since. If you have questions concerning your project, please create a new topic, with details. Thanks.