-1

I have a code to turn on a LED when IR Proximity sensor having a object less than 6cm in front of it, and the LED goes down after it is removed.

Now, I want the LED to run for 3 seconds only, even if the object is not removed, how should I modify my code? Many thanks in advance!

int LED = 13; // pin for the LED
int Sensor = 2;// pin for the IR Sensor

void setup(){

  pinMode (LED, OUTPUT); 
  pinMode (Sensor, INPUT);
}

void loop(){



  if (digitalRead(2)){

      digitalWrite(LED , LOW); 
  }

  else{

    digitalWrite ( LED, HIGH);
    // if the IR sensor detects an object, the LED turns on or else it should not turn on 
}
1
  • what are you doing? ... you already asked this question, and it was answered, and you accepted the answer – jsotola Jun 8 '20 at 0:18
0
int LED = 13; 
int Sensor = 2;

void setup(){

  pinMode (LED, OUTPUT); 
  pinMode (Sensor, INPUT);
} 

void loop(){

 if (digitalRead(2)){

        digitalWrite(LED , LOW); 
        delay(3);
  }

 else{

    digitalWrite ( LED, HIGH);``
 }
1
  • I do not see any relation to the question, sorry. – DataFiddler Jun 15 '20 at 11:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.