RFID Reader to turn on LED

Ive seen lots of tutorials online and tried to follow along with them. I can get this project working when i use the example codes and modify them. However this code i wrote from scratch and cant seem to get it to work.

My serial monitor just show “GO” and then nothing after that. Any ideas how to fix this?

Im also getting an error when verifying "warning: invalid conversion from ‘byte* {aka unsigned char*}’ to ‘byte {aka unsigned char}’ [-fpermissive]

byte correcttag = taga;

^~~~

C:\Users\Escape Artist AZ\Documents\Sketches\RFID_Read_1-18-21\RFID_Read_1-18-21.ino: In function ‘void checkcorrect()’:

RFID_Read_1-18-21:69:33: error: invalid types ‘byte {aka unsigned char}[int]’ for array subscript

if (lasttag[0] == correcttag[0] ||

^

RFID_Read_1-18-21:70:33: error: invalid types ‘byte {aka unsigned char}[int]’ for array subscript

lasttag[1] == correcttag[1] ||

^

RFID_Read_1-18-21:71:33: error: invalid types ‘byte {aka unsigned char}[int]’ for array subscript

lasttag[2] == correcttag[2] ||

^

RFID_Read_1-18-21:72:33: error: invalid types ‘byte {aka unsigned char}[int]’ for array subscript

lasttag[3] == correcttag[3] )

^

exit status 1

invalid types ‘byte {aka unsigned char}[int]’ for array subscript

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.
"

FULL CODE BELOW

#include <SPI.h>
#include <MFRC522.h>

//define used pins
byte sdapin = 53;
byte resetpin = 5;
byte greenpin = 8;
byte redpin = 9;

//begin scanning
MFRC522 scannerone(sdapin, resetpin);
MFRC522::MIFARE_Key structure;

//UIDs of each tag
byte taga[4] = {167, 195, 90, 214};
byte tagb[4] = {103, 218, 138, 198};
byte tagc[4] = {167, 98, 177, 199};
byte tagd[4] = {51, 231, 169, 61};
byte tage[4] = {32, 154, 91, 47};
byte tagf[4] = {32, 208, 250, 47};

//stores the UID of the last tag scanned
byte lasttag[4] = {00, 00, 00, 00};

byte correcttag = taga;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  SPI.begin(); // Init SPI bus
  scannerone.PCD_Init(); // Init MFRC522

  for (byte i = 0; i < 6; i++) {
    structure.keyByte[i] = 0xFF;
  }

  pinMode(greenpin, OUTPUT);
  pinMode(redpin, OUTPUT);
  Serial.println("GO");
}

void loop()
{
  // put your main code here, to run repeatedly:

  if (scannerone.PICC_ReadCardSerial() == 1)
  {
    Serial.println("Good");
    if (scannerone.uid.uidByte[0] != lasttag[0] ||
        scannerone.uid.uidByte[1] != lasttag[1] ||
        scannerone.uid.uidByte[2] != lasttag[2] ||
        scannerone.uid.uidByte[3] != lasttag[3] )
    {
      Serial.println("A new card has been detected.");

      // Store NUID into lasttag array
      for (byte i = 0; i < 4; i++)
      {
        lasttag[i] = scannerone.uid.uidByte[i];
        Serial.println(scannerone.uid.uidByte[i]);
      }
      Serial.println(lasttag[1]);
      checkcorrect();
    }
  }
}
void checkcorrect()
{
  if (lasttag[0] == correcttag[0] ||
      lasttag[1] == correcttag[1] ||
      lasttag[2] == correcttag[2] ||
      lasttag[3] == correcttag[3] )
  {
    digitalWrite(greenpin, HIGH);
  }
}

True. You declare 'correcttag' as a byte, then try to use it as an array, 'correcttag[0]'. See?

How can i set correcttag to taga? Do i have to do a for statement and set each part individually?

Bump

Change:

byte correcttag = taga;

to:

byte *correcttag = taga;

What is the purpose of the asterisk? I’ve seen it in a couple codes but I don’t know what it’s for.

escapeartistaz:
What is the purpose of the asterisk? I’ve seen it in a couple codes but I don’t know what it’s for.

Pointer. You can review C/C++ tutorials. Here is one:

C Pointers

Ive changed correct tag to a pointer. Still when i run my program i get "go" during my setup. Then nothing after that.

Still need answers on this. My reader is not sending anything to the serial monitor

bump

Can anyone answer this?

Im still hard stuck in the same spot if anyone can help please

SOMEONE PLEASE PLEASE PLEASE HELP ME

Please

help

Post your latest sketch and I will try to help.

This is the most up to date version. It just says go then nothing.

#include <SPI.h>
#include <MFRC522.h>

//define used pins
byte sdapin = 53;
byte resetpin = 5;
byte greenpin = 8;
byte redpin = 9;

//begin scanning
MFRC522 scannerone(sdapin, resetpin);
MFRC522::MIFARE_Key structure;

//UIDs of each tag
byte taga[4] = {167, 195, 90, 214};
byte tagb[4] = {103, 218, 138, 198};
byte tagc[4] = {167, 98, 177, 199};
byte tagd[4] = {51, 231, 169, 61};
byte tage[4] = {32, 154, 91, 47};
byte tagf[4] = {32, 208, 250, 47};

//stores the UID of the last tag scanned
byte lasttag[4] = {00, 00, 00, 00};

byte *correcttag = tagf;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  SPI.begin(); // Init SPI bus
  scannerone.PCD_Init(); // Init MFRC522

//  I DONT REMEMBER WRITING THIS CAN ANYONE TELL ME WHAT ITS FOR???
  for (byte i = 0; i < 6; i++) {
    structure.keyByte[i] = 0xFF;
  }

  pinMode(greenpin, OUTPUT);
  pinMode(redpin, OUTPUT);
  digitalWrite(redpin, HIGH);
  Serial.println("GO");
}

void loop()
{
  // put your main code here, to run repeatedly:

  if (scannerone.PICC_ReadCardSerial() == 1)
  {
    if (scannerone.uid.uidByte[0] != lasttag[0] ||
        scannerone.uid.uidByte[1] != lasttag[1] ||
        scannerone.uid.uidByte[2] != lasttag[2] ||
        scannerone.uid.uidByte[3] != lasttag[3] )
    {
      Serial.println("A new card has been detected.");
      // Store NUID into lasttag array
      for (byte i = 0; i < 4; i++)
      {
        lasttag[i] = scannerone.uid.uidByte[i];
        Serial.println(scannerone.uid.uidByte[i]);
      }
      checkcorrect();
    }
  }
}

void checkcorrect()
{
  if (lasttag[0] == correcttag[0] ||
      lasttag[1] == correcttag[1] ||
      lasttag[2] == correcttag[2] ||
      lasttag[3] == correcttag[3] )
  {
    digitalWrite(greenpin, HIGH);
  }
}

Have you added some Serial.println statements into the loop() function to see if it is running? Try the loop() function I have below and see what prints.

Like this:

void loop()
{
  // put your main code here, to run repeatedly:

  Serial.println("Enter loop()");
  if (scannerone.PICC_ReadCardSerial() == 1)
  {
    if (scannerone.uid.uidByte[0] != lasttag[0] ||
        scannerone.uid.uidByte[1] != lasttag[1] ||
        scannerone.uid.uidByte[2] != lasttag[2] ||
        scannerone.uid.uidByte[3] != lasttag[3] )
    {
      Serial.println("A new card has been detected.");
      // Store NUID into lasttag array
      for (byte i = 0; i < 4; i++)
      {
        lasttag[i] = scannerone.uid.uidByte[i];
        Serial.println(scannerone.uid.uidByte[i]);
      }
      checkcorrect();
    }
    else
    {
       Serial.println("Same card");
    }
  }
  else
  {
     Serial.println("PICC_ReadCardSerial() failed");
  }
  Serial.println("Exit loop()");
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.