# Is there a way to have the LED switch on after 10 readings or say a minute?

I am using Arduino for a RFID project where the LED must switch on after either 12 readings of the tag or 2 minute, the tag reading happen every 10 seconds. I can't seem to figure out a way to have the LED switch on only after the above mentioned conditions.

I have tried doing various if loop much to my failure, below is the code I am currently using:

#include <RFID.h>
#include <SPI.h>
#define SS_PIN 10
#define RST_PIN 9
#define LED_PIN A0
RFID rfid(SS_PIN, RST_PIN);
int serNum[5];
String cardno;
int interval = 15000; // millisec
long now = 0;
long lasttime = millis();
void setup() {
Serial.begin(9600);
SPI.begin();
rfid.init();
pinMode(A0, OUTPUT);
}

void loop() {
now = millis();
if (now > lasttime + interval) {
lasttime = now;
Serial.print(":");
Serial.println("I am alive");
}
if (rfid.isCard()) {
lasttime = now;
cardno = String(rfid.serNum[0]) +
String(rfid.serNum[1]) +
String(rfid.serNum[2]) +
String(rfid.serNum[3]) +
String(rfid.serNum[4]);

Serial.print(":");
Serial.println(cardno);
}
}
rfid.halt();
delay(10000);
}


The expected outcome is the LED switching on after 2 minutes of contact between the tag and the reader.

• Presumably you want a counter that increments on each success, and some kind of time limit that resets the count after a long enough gap, for which you probably want to be storing the time of the last success. – Chris Stratton Apr 19 at 16:31
• yes exactly but I can't figure out how to do that – Ayat.H Apr 19 at 16:49
• First get rid of the delay(). Then consider making a sketch that prints a running count of the number of reads. Then think about how you can determine how much time has elapsed since the last read and print that. Then think about how you can take action when that amount of time since the last read exceeds some threshold... – Chris Stratton Apr 19 at 16:52
• i am a complete beginner at using arduino, can you suggest some commands? do you think millis would work? – Ayat.H Apr 19 at 17:10
• I had another question, is there a way to connect 2 arduino boards as in where the output on one board determines the output on the other? – Ayat.H Apr 19 at 17:10