arduino timer

im new on arduino and im trying to do a alarm with a led, a buzzer and a movement detector.
The problem i have is that when the movement detector detects something moving the led starts blinking and the buzzer ringing but when it stops moving it stops automatically. i need to make it sound for 10 secs but i already used delay in the loop and i cant use delay anymore because of the leds.
Heres the code:

brunzidor_casa_arduino.ino (495 Bytes)

It's easier for us if you incorporate the code in your post (using code tags) instead of as attachment.

[code] your code here [/code] will result in

 your code here

The solution to the problem is to use a non-blocking delay (actually all your delays should be non-blocking); see the BlinkWithoutDelay example that comes with the IDE).

I've only implemented the main timing and kept your delays in place.

// variable to keep track of current 'time'
unsigned long currentMillis;

void loop()
  // starttime of beep / buzz; also used as a flag to indicate that beep / buzz is in progress for 10 seconds
  static unsigned long starttime = 0;

  // get current 'time'
  currentMillis = millis();

  int value = digitalRead(PIRPin);

  // if triggered or beep / buzz in progress
  if (value == HIGH || starttime != 0) {
    // set start time
    starttime = currentMillis;
    tone(9, 1500);
    digitalWrite(LEDPin, HIGH);
    digitalWrite(LEDPin, LOW);

    // check if beep / buzz duration has lapsed
    if(currentMillis - starttime >= 10000)
      // indicate 10 seconds passed
      starttime = 0;
    digitalWrite(LEDPin, LOW);
    tone(10000, 00);

Quick and dirty implementation (as said, you should get rid of delays); not tested. Read Demonstration code for several things at the same time and check the BllinkWithoutDelay example.

thanks ^^