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

http://farm7.staticflickr.com/6096/6382 … df90_m.jpg

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.

This should help. [www.rfid.net](http://www.rfid.net)