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
}