Unwanted delay

Hi all,
I’m new at Arduino and C++ in general and I can’t for the life of me figure out where I am going wrong.
I am trying to create a sketch using the Arduino Uno r3 and the RC522 Rfid reader.
I’m using addicoreRFID.h
The purpose of the Sketch is to output a high on pin 7 when there is a high on pin 6 AND the correct card is on the reader.
It is working perfectly…almost…
I have an LED indicating if pin 7 is high or low and I’m using a loop from the 5v rail to pin 6 to simulate a high there.
When I put the right card on the reader and the loop to pin 6 is present the LED lights
When I remove the card the LED goes out.
If the card is present and I break the loop to pin 6 the LED goes out…eventually (a few seconds later, timing varies)
I’m trying to work out the cause of the delay when the loop to pin 6 is broken.
Any help would be appreciated.

Code below:

#include <AddicoreRFID.h>
#include <SPI.h>

#define uchar unsigned char
#define uint unsigned int

uchar fifobytes;
uchar fifoValue;

AddicoreRFID myRFID; // create AddicoreRFID object to control the RFID module

//set the pins
const int chipSelectPin = 10;
const int NRSTPD = 5;
int tenIn = 1;
int jackIn = 2;
int queenIn = 3;
int kingIn = 4;
bool val = 0;
//Maximum length of the array
#define MAX_LEN 16

void setup() {
Serial.begin(9600); // RFID reader SOUT pin connected to Serial RX pin at 9600bps

// start the SPI library:

pinMode(chipSelectPin,OUTPUT); // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(chipSelectPin, LOW); // Activate the RFID reader
pinMode(NRSTPD,OUTPUT); // Set digital pin 10 , Not Reset and Power-down
digitalWrite(NRSTPD, HIGH);

pinMode(tenIn, INPUT);
pinMode(jackIn, INPUT);
pinMode(queenIn, INPUT);
pinMode(kingIn, INPUT);
pinMode(6, INPUT);
pinMode(7, OUTPUT);

digitalWrite(7, LOW);


void loop()
val = digitalRead(6);
if (val == 1)
uchar i, tmp, checksum1;
uchar status;
uchar str[MAX_LEN];
uchar card[4] = {67, 114, 190, 57}; //set acceptable card
uchar RC_size;
uchar blockAddr; //Selection operation block address 0 to 63

status = myRFID.AddicoreRFID_Request(PICC_REQIDL, str);

//Anti-collision, return tag serial number 4 bytes
status = myRFID.AddicoreRFID_Anticoll(str);
if (status == MI_OK)
val = digitalRead(6);
if((str[0] == card[0]) && (str[1] == card[1]) && (str[2] == card[2]) && (str[3] == card[3]) && (val == 1)) //add "&& (digitalRead(tenIn)== HIGH) up to King if Ace board
digitalWrite(7, HIGH);
digitalWrite(7, LOW);
digitalWrite(7, LOW);
digitalWrite(7, LOW);
myRFID.AddicoreRFID_Halt(); //Command tag into hibernation


Have you got pulldown resistors holding the input pins LOW when you do not connect them to 5V to activate them ? If not then you cannot be sure of the voltage on them when not explicitly taking them HIGH. This could keep the pins HIGH even when you don't want them to be.

The easiest way to deal with this is to use INPUT_PULLUP in the pinMode()s to activate the built in pullup resistors, change the wiring to take the pins LOW to activate them and change the program logic to match.

Thanks UKHeliBob, I'll look into that tomorrow and see if that solves the problem

Thanks UKHeliBob - that was the issue, it's all working great now. :)