Paste this into an empty Arduino IDE and try it
/* simple untested LDR trigger for Moon (the Robot). Smoothing may be required.
See the “analog > smoothing” example on the official arduino website */
boolean firstTrigger=false; //tells the duino if the LDR level is below 100
const int sensor=0; //or whatever your LDR sensor is.
const int MotorPin1 = 4; //or whatever
const int MotorPin2 = 5; //or whatever
void setup(){
//initialise your motor pins
pinMode(MotorPin1,OUTPUT);
pinMode(MotorPin2,OUTPUT);
}
void loop(){
//trigger timer loop by initial activation.
if (analogRead(sensor) < 100){
//2 second timer loop. LDR of greater than 100 will break the loop, thus going back to start
for (int i=0; i < 200; i++){
if (analogRead(sensor) > 100) break;
if (i == 200) firstTrigger=true;
delay(10);//10 x 200 = 2000 ms = 2 seconds
}
}
//we’ve made it at least 2 seconds on low
if (firstTrigger){
if (analogRead(sensor) > 400) Motor();
}
}//end of primary loop
void Motor(){
//assumes an H-bridge of some sort
digitalWrite(MotorPin1,HIGH);
digitalWrite(MotorPin2,LOW);
}