controling 5 leds at diferent time

Hi all im new to arduino and i have a problem i want to control 5leds at diferent time of closing and opening im using a LDR to set the triger for the leds my problem is that my code works only with one led i hope you can help me thank you here is my code so far.
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
int sensorValue = analogRead(A0);
if (sensorValue > 400) { // To change the point at which the light turns on change this value.
digitalWrite(13, HIGH);
delay(5000);
}
else {
digitalWrite(13,LOW);
}
}

This video may help: it shows how to handle two leds with independent timing.

See if this gives you some ideas:
EDIT: Added currentmillis = millis();
to the sketch

//State machine skeleton

const unsigned long TaskAppleWait  = 5000UL; //Runs Task every 5 Sec 
const unsigned long TaskOrangeWait = 100UL;  //Runs Task every 100ms
const unsigned long TaskPearWait   = 500UL;  //Runs Task every 1/2Sec
const unsigned long TaskKiwiWait   = 1000UL; //Runs Task every 1Sec
//add more as needed

unsigned long TimeApple;                     //Times up, run TaskApple
unsigned long TimeOrange;                    //Times up, run TaskOrange
unsigned long TimePear;                      //Times up, run TaskPear
unsigned long TimeKiwi;                      //Times up, run TaskKiwi
//add more as needed

unsigned long currentmillis; 

//other variables

//define the available states that we can have for this sketch
enum States{
  stateWait, stateApple, stateOrange, statePear, stateKiwi};
//add more states as needed
States mState = stateWait;             //we start out in this machine state 


//========================================================== 
void setup()
{
  Serial.begin(9600);

  currentmillis = millis();
  TimeApple  = currentmillis;            //initailize all times 
  TimeOrange = currentmillis;            //
  TimePear   = currentmillis;            //
  TimeKiwi   = currentmillis;            //

  pinMode(13,OUTPUT);                    //
  pinMode(12,OUTPUT);                    //
  pinMode(11,OUTPUT);                    //
  pinMode(10,OUTPUT);                    //
  //Go to an idle condition
  mState = stateWait;                    //we start out in this machine state 

} //        >>>>>>>>>>>>>> END OF setup() <<<<<<<<<<<<<<<<<


void loop()
{
 //leave this line here
 currentmillis = millis();

  if (mState == stateWait)
  {
    int sensorValue = analogRead(A0);

    if (sensorValue >= 400 && sensorValue < 500) 
    { // To change the point at which the light turns on change this value.
      mState = stateApple;
      TimeApple = millis();
      //turn on the led on D13
      digitalWrite(13, HIGH);  
    }    
    
    else if (sensorValue >= 500 && sensorValue < 600) 
    { // To change the point at which the light turns on change this value.
      mState = statePear;
      TimePear = millis();
      //turn on the led on D12
      digitalWrite(12, HIGH);  
    }

    //    else if (sensorValue >= 600 && sensorValue < 700) 
    //    { // To change the point at which the light turns on change this value.
    //      mState = stateOrange;
    //      TimeOrange = millis();
    //      //turn on the led on D11
    //      digitalWrite(11, HIGH);  
    //    }
    //      ETC. . . 

  }  //end of if (mState == stateWait)


  //*********** Other loop stuff goes here ************ 



  //************** State Machine section ************** 
  switch (mState)
  {
    //***************************
  case stateWait:

    break;

    //***************************
  case stateApple:

    //is it time to run this section of code?
    if (CheckTime(TimeApple, TaskAppleWait)) 
    {
      //Turn off the led on D13 
      digitalWrite(13, LOW);
      //Go back to an idle condition
      mState = stateWait;
    }

    break;

    //***************************
  case stateOrange:
    //is it time to run this section of code?
    if (CheckTime(TimeOrange, TaskOrangeWait)) 
    {
      //Turn off the led on D12 
      digitalWrite(12, LOW);
      //Go back to an idle condition
      mState = stateWait;
    }

    break;

    //***************************
  case statePear:

    //is it time to run this section of code?
    if (CheckTime(TimePear, TaskPearWait)) 
    {
      //some code
    }

    break;

    //***************************
  case stateKiwi:

    //is it time to run this section of code?
    if (CheckTime(TimeKiwi, TaskKiwiWait)) 
    {
      //some code
    }

    break;

    //***************************
  default: 
    // statements
    break;

    //***************************
  }   // end of switch/case


} //        >>>>>>>>>>>>>> END OF loop() <<<<<<<<<<<<<<<<<



//                    F U N C T I O N S
//========================================================== 

//Delay time expired function
boolean CheckTime(unsigned long &lastMillis, unsigned long wait) {

  //has the time expired? 
  if (currentmillis - lastMillis >= wait) 
  {
    lastMillis += wait;  //get ready for the next timing cycle

    return true;
  }

  return false;

} //END of CheckTime()

//==================




//======================================================================
//                             END OF CODE
//======================================================================

Added currentmillis = millis(); to the sketch

OP, you can go look at the "BlinkWithoutDelay" sketch in the IDE Examples menu to see the basics. You can use any number of that same routine, one for each Led. Just duplicate the guts of BlinkWithoutDelay sketch for each Led.

Larry, your code is somewhat complex for a first-time noobee like myself, but I'm scratching my twitchy head and trying to understand it. It seems to me, if your sensor readings are changing fairly quickly and your timing-delays are non-trivial, that you may never get back into the state of your FSM down below that turns off the Led that was turned on [and the state set] up above.

I think I would have had separate flags up above, rather than a single state variable, and each of the routines inside the states down below re-positioned separately in the main loop, and activated by the flags.

BTW, your function CheckTime() is very handy, and I use an almost identical routine myself. I also prefer ... lastMillis=currentmillis; ... over ... lastMillis += wait; ... inside the if-check.

Larry, your code is somewhat complex for a first-time noobee like myself, but I'm scratching my twitchy head and trying to understand it. It seems to me, if your sensor readings are changing fairly quickly and your timing-delays are non-trivial, that you may never get back into the state of your FSM down below that turns off the Led that was turned on [and the state set] up above.

Yes a bit complex.
if (mState == stateWait)
Prevents any readings till the the led is off (not ideal) just added this example to give some ideas.
Wanted to give an idea for a state machine.
By the way, from what I have read, I think you are an oldie not a noobee. :wink:

Edit, not a software person, 43 years in hardware.