Programming RFID

Im stuck on trying to figure out how to make the rfid stay activated after the tag comes in range and stay on until it comes in range again, then turn off. could anyone help or tell me if this is possible? thanks.

What do you mean by "make the rfid stay activated".

You have left out all the details. Why don't you think for a minute about how much those of us here on the forum actually know about your project? Think about what we might need to know in order to help you. Post your code if you want help with the code.

sorry about that, this is my first time posting in here. My project is a doghouse that has several sensors activated when the rfid tag comes in range but then quits running the code when the tag get out of range. This is the code i have so far. it only runs the code for about 2 seconds and turns off and on in that interval when the tag is still in range. i am using a parallax RFID 28140

int val = 0;
char code[10];
int bytesread = 0;

void setup() {

Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(2, LOW); // Activate the RFID reader
}

void loop() {

if(Serial.available() > 0) { // if data available from reader
if((val = Serial.read()) == 10) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( Serial.available() > 0) {
val = Serial.read();
if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
if(bytesread == 10) { // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
}
bytesread = 0;
digitalWrite(2, HIGH); // deactivate the RFID reader for a moment so it will not flood
delay(1500); // wait for a bit
digitalWrite(2, LOW); // Activate the RFID reader
}
}
}

Ok. That code reads a tag. You also mentioned something about a doghouse? You'll probably want some code to check if the tag you got was the right tag. That's been done so many times before. I'm not going to redo it here.

You can get the value from millis() which will tell you how many milliseconds have passed since the board was started. If you know the time that you first read the good rfid then you can compare to that time to decide to look for another rfid or do something else. See the "Blink Without Delay" example and the innumerable tutorials about it for more info on millis.

@zackschexnider, do not cross-post. Other thread removed.

My project is a doghouse that has several sensors activated when the rfid tag comes in range but then quits running the code when the tag get out of range.

Take a deep breath and try again. This collection of words is nonsense.

You should get the RFID reader off the hardware serial pins so you can debug the code. SoftwareSerial works perfectly well reading at that slow speed.

Why do you feel it necessary to disconnect and reconnect the reader? What does that have to do with the "several sensors" that don't seem to exist? Do you plan to turn them off and on, too?