rfid reader, temperature sensor and light sensor

i need help in making an ID-12 rfid reader read a tag, display information on the serial port and allow a temperature sensor and light sensor to update their readings every second while waiting for another tag to be read. i only manage to display the tag id, tag name attached to the id, and show the temperature sensor and light sensor reading only once.

#include <SoftwareSerial.h>



 #define rxPin 7 
 #define txPin 5


SoftwareSerial rfid = SoftwareSerial( rxPin, txPin );


#define tempSensePin 5
#define lightSensePin 1
#define templedPin 10
#define lightledPin 5



#define tempsecs 1
#define lightsecs 1


char* allowedTags[] = {
  "4500F36C96",         // Tag 1
  "4500F39C0A",         // Tag 2
  
};

// List of names to associate with the matching tag IDs
char* tagName[] = {
  "Peter",      // Tag 1
  "Kahiga",      // Tag 2
  
};


int numberOfTags = sizeof(allowedTags)/sizeof(allowedTags[0]);

int incomingByte = 0;    // To store incoming serial data


void setup() {
  pinMode(templedPin, OUTPUT);
  pinMode (lightledPin, OUTPUT);
  digitalWrite(templedPin, LOW);
  digitalWrite(lightledPin, LOW);
  
  
  
  analogReference (DEFAULT);

  Serial.begin(9600);   // Serial port for connection to host
  rfid.begin(9600);      // Serial port for connection to RFID module


}


void loop() {
  
  rfid_read();  
}
  
  void rfid_read(){
    
  byte i         = 0;
  byte val       = 0;
  byte checksum  = 0;
  byte bytesRead = 0;
  byte tempByte  = 0;
  byte tagBytes[6];    // "Unique" tags are only 5 bytes but we need an extra byte for the checksum
  char tagValue[10];

  if((val = rfid.read()) == 2) {      
    bytesRead = 0;
    while (bytesRead < 12) {            
      val = rfid.read();

      // Append the first 10 bytes (0 to 9) to the raw tag value
      if (bytesRead < 10)
      {
        tagValue[bytesRead] = val;
      }

      // Check if this is a header or stop byte before the 10 digit reading is complete
      if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) {
        break;                          // Stop reading
      }

      // Ascii/Hex conversion:
      if ((val >= '0') && (val <= '9')) {
        val = val - '0';
      }
      else if ((val >= 'A') && (val <= 'F')) {
        val = 10 + val - 'A';
      }

      // Every two hex-digits, add a byte to the code:
      if (bytesRead & 1 == 1) {
        // Make space for this hex-digit by shifting the previous digit 4 bits to the left
        tagBytes[bytesRead >> 1] = (val | (tempByte << 4));

        if (bytesRead >> 1 != 5) {                // If we're at the checksum byte,
          checksum ^= tagBytes[bytesRead >> 1];   // Calculate the checksum... (XOR)
        };
      } else {
        tempByte = val;                           // Store the first hex digit first
      };

      bytesRead++;                                // Ready to read next digit
    }

    // Send the result to the host connected via USB
    
    if (bytesRead == 12) {                        // 12 digit read is complete
      tagValue[10] = '\0';                        // Null-terminate the string

      Serial.print("Tag Id: ");
      for (i=0; i<5; i++) {
        // Add a leading 0 to pad out values below 16
        if (tagBytes[i] < 16) {
          Serial.print("0");
        }
        Serial.print(tagBytes[i], HEX);
      }
      Serial.println();

      int tagId = findTag( tagValue );

      // Only start the other systems if this tag was found in the database
      if( tagId > 0 )
      {
        Serial.print("Welcome ");
      
        Serial.println(tagName[tagId - 1]);   // Get the name for this tag from the database
        
        temp();          // Start the temperature control system
        light();         // start the lighting control system
        
        
      } else {
        Serial.println("Tag not authorized");
      }
      Serial.println();     // Blank separator line in output
    }

    bytesRead = 0;
  }
}

void temp() {
  int val = analogRead(tempSensePin); 
  Serial.println (val);
  delay(tempsecs * 1000);
  val = constrain (val, 580, 585); 
  int ledLevel = map (val, 580, 590, 255, 0);
  analogWrite (templedPin, ledLevel);
  
}

void light ()
{
  int val = analogRead(lightSensePin); 
  Serial.println (val);
  delay(lightsecs * 1000);
  val = constrain (val, 15, 180);
  int ledLevel = map (val, 15, 180, 255, 0);
  analogWrite (lightledPin, ledLevel);
}

/**
 * Search for a specific tag in the database
 */
int findTag( char tagValue[10] ) {
  for (int thisCard = 0; thisCard < numberOfTags; thisCard++) {
    // Check if the tag value matches this row in the tag database
    if(strcmp(tagValue, allowedTags[thisCard]) == 0)
    {
      // The row in the database starts at 0, so add 1 to the result so
      // that the card ID starts from 1 instead (0 represents "no match")
      return(thisCard + 1);
    }
  }
  // If we don't find the tag return a tag ID of 0 to show there was no match
  return(0);
}

the output is as shown below

the first value is the temperature and the second value the light intensity. i like help with code for updating the temperature and light intensity every second, read a second card and display the details of the tag then continue updating the temperature and light intensity.

SoftwareSerial rfid = SoftwareSerial( rxPin, txPin );

SoftwareSerial is obsolete. You should be using NewSoftSerial, instead.

void loop() {
  rfid_read();  
}

And the temperature and light sensors are not read. I wonder why.

        temp();          // Start the temperature control system
        light();         // start the lighting control system

Why is this in with reading the RFID data?

You need to get rid of the delay() calls in temp() and light(). While delay() is executing in those two functions, you can't read an RFID tag.

You'll need to look at the blink without delay example.

my problem isnt that the rfid cards aren't read, it is that i cant be able to loop through the temperature and light intensity values continuously so as to display the value i get on the arduino com port in real time. please help.

it is that i cant be able to loop through the temperature and light intensity values continuously so as to display the value i get on the arduino com port in real time.

You can't for two reasons. First, you only call the functions to get the temperature and light intensity when a valid tag has been scanned.

Make the calls in loop, not in the rfid tag reader function.

The second reason you can't do it is the delays in the two functions. The delay() function and "in real time" don't go together. Figure out whether you mean "in real time" or "once a second, and do nothing in between reads".

i have called the functions in the loop and removed the delay though i need periodical updates at 1 second intervals of the temperature and light intensity but it the result is still the same.i need help making the temperature and light intensity values loop cotinuously until another rfid tag is read, hence interrupting the readings but resume right after the tag details are displayed until the system exits the temp ad light loops work fine on their own but when combined with rfid code the looping stops. any help will be highly appreciated.

i have

modified the code, but am leaving it to you to guess how.

I don't think it works that way.

You need to call the three functions - to get the temp, light intensity, and see if there is a tag to read - every pass through loop. You need to use millis() to see if it is time to output new values, but that seems to defeat the purpose of "real time" readings. Unless you have a different definition of real time that I do.