Code for the trouble program 3 (much easier than downloading!):
/*
RFID SunFounder Uno
VCC 3.3V
RST 2
GND GND
MISO 3
MOSI 4
SCK 5
NSS 6
IRQ 7
****************************************/
#include"rfid.h"
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
RFID rfid; //create a variable type of RFID
#define relayPin 8 //relay module attach to pin8
uchar serNum[5]; // array to store your ID
void setup()
{
lcd.init(); //initialize lcd
lcd.backlight(); //turn on the backlight
Serial.begin(9600);
rfid.begin(7, 5, 4, 3, 6, 2); //IRQ_PIN,SCK_PIN,MOSI_PIN,MISO_PIN,NSS_PIN,RST_PIN
delay(100);
rfid.init(); //initialize the RFID
pinMode(relayPin, OUTPUT); //set relayPin as OUTPUT
digitalWrite(relayPin, LOW); //and high level
delay(2000); //delay 2s
}
void loop()
{
uchar status;
uchar str[MAX_LEN];
// Search card, return card types
status = rfid.request(PICC_REQIDL, str);
if (status != MI_OK)
{
return;
}
// Show card type
rfid.showCardType(str);
//Prevent conflict, return the 4 bytes Serial number of the card
status = rfid.anticoll(str);
if (status == MI_OK)
{
Serial.print("The card's number is: ");
memcpy(serNum, str, 5);
rfid.showCardID(serNum); //show the card ID
Serial.println();
// Check people associated with card ID
uchar* id = serNum;
if (id[8] == 0X45 && id[2] == 0X08 && id[3] == 0X7A && id[4] == 0XFE)
{
digitalWrite(relayPin, HIGH);
}
else
{
digitalWrite(relayPin, LOW);
}
}
rfid.halt(); //command the card into sleep mode
}
A few things of note.
- In line 54 you're looking for an id[8] while the array is only 5 characters long.
- That are not regular ASCII characters you're looking for. That probably explains why you don't do a strcmp(), but doesn't make sense in relation to your description of what the serial numbers should look like.