Hi i am using a PIR Sensor. I have connected a LED on pin 13 to the PIR Sensor. I need to blink the LED for 10 seconds when ever the pir sensor goes high. I used a delay(1000) command. But mean while my other components connected to the Arduino is not working during that 10 seconds. I need to use Blink with out LED command. I dont know how to interface with my existing command. My PIR code is as follows
void pirSensor() // called using a function.
{
pirVal = digitalRead(pir);
if (pirVal == HIGH)
{
digitalWrite(pirLED, HIGH); // turn LED ON
delay(10000); // delay for 10 sec.
}
else
{
digitalWrite(pirLED, LOW); // turn LED ON
}
}
blink led with out using a delay command code is as follows
const int ledPin = 13; // LED on pin 13, won't change so constant
int pir = 6;
int pirval = 0;
const long delayTime = 10000; // delay required (ms)
boolean ledState = true; // state of the LED, initially L(off)
unsigned long previousMillis = 0; // variable to store last time LED blinked
unsigned long currentMillis = 0; // variable to store current time
void setup() {
pinMode(ledPin, OUTPUT); // set pin direction
Serial.begin (9600);
}
void loop()
{
pirval = digitalRead(pir);
if (pirval == HIGH)
{
currentMillis = millis();
previousMillis = millis();
// we then check whether the time between now and last time we blinked
// LED is greater than the specified delay
if (currentMillis - previousMillis > delayTime ) {
// if above statement is TRUE, code inside brackets is executed....
ledState = !ledState;
digitalWrite(ledPin, ledState); // turn LED ON
Serial.print(ledState);
}
}
else {
digitalWrite (ledPin,LOW);
}
}
help me with the above code and sort out my mistake please !!!!!!