using phototransistors

we are doing this project (power monitor), what we did was to used 3 LEDs with different power supply, connected to three different devices. each LED faces a photo transistor, which will be monitoring the changes in the power state. each photo transistor is then connected to three different ports in the module (arduino clone with ATmege 328).
the program device should work this way:

if sensor1 is off, send a message, run timer
while sensor1 is off and sensor 2 is off send a message, while the timer is still running
while sensor1 and sensor2 and sensor3 is off, send a message, while the timer is running
if sensor1 is on, stop timer and send a message with the total time

we only had the codes for receiving the inputs and starting the timer.
the sending of the message will be carried out by a GSM module.
PROBLEMS:
-how to calculate time accurately
-how does the code for the GSM module be inserted to successfully send message
-can we pass a value of a variable(for instance the value of the timer) to the message
-what other things can we do to improve our design?

Background:
-line following robot construction using Zilog042A MCU, and Zilog6421
-LED manipulation using Atmel2051

const int deviceOne = 3;
const int deviceTwo = 4;
const int deviceThree = 5;
const int ledOut = 13;


int stateOne = 0;
int stateTwo = 0;
int stateThree = 0 ;
int msgFlag = 0;
int second = 0;
int minute = 0;
int hours = 0;

void setup() {                
  
  pinMode(deviceOne, INPUT); 
  pinMode(deviceTwo, INPUT); 
  pinMode(deviceThree, OUTPUT);  
  pinMode(ledOut, OUTPUT);      
}


void loop() {
  stateOne = digitalRead(deviceOne);
  stateTwo = digitalRead(deviceTwo);
  stateThree = digitalRead(deviceThree);
  
  if(stateOne==LOW)
  {  
    //send message OFF
    msgFlag = 1;
      
  }
  while(stateOne == LOW)
  {
    //start count;
   while(second <60)
   {
       second++;
       delay(1000);
       
       if(second == 60)
       {
         minute++;
         second = 0;
       }
   
       if(minute == 60)
       {
         hours++;
         minute = 0;
       }
   }
  }
    if(stateTwo == LOW)
  {      //send message OFF
  
    while(second <60)
   {
       second++;
       delay(1000);
       
       if(second == 60)
       {
         minute++;
         second = 0;
       }
   
       if(minute == 60)
       {
         hours++;
         minute = 0;
       }
   }
  
  
  }
  
   
   if(stateThree == LOW)
  {   
    //send message OFF
   while(second <60)
   {
       second++;
       delay(1000);
       
       if(second == 60)
       {
         minute++;
         second = 0;
       }
   
       if(minute == 60)
       {
         hours++;
         minute = 0;
       }
   }
  }
  };

  if ((stateOne == HIGH) & (msgFlag == 1)) 
  {
    //send message ON
    msgFlag = 0;
    //get time value
  }
   
}