Sound a buzzer

Hi All,
I’m building a little simple PIR alarm using NRF24l01 module, All this is working and the buzzer just sounds for a second or so but would like it to give more time causing a bleeping effect say for 2 minutes.
How it’s works at the moment the transmitter sends out an 10 when no motion detected then when motion is detected it sends out a 12, The receiver does nothing while 10 is coming in then once a 12 is received the buzzer just sounds for a second or so and it keeps repeating this only when motion is detected so it’s working in a fashion but not giving alarm type sound, it’s more like a door chime at the moment.
Ideally I would like it to give bleep bleep bleep say for 2 minutes, I’ve tried several ways but only get that continuous bleep for a second or so. I did try a while loop which ran once then but it seem to got stuck in the buzzer part,
Here is my code so far keep trying different ways but still get the same effect so I thought I’d stop and ask here, I know there may be a simple way but cannot see the wood through the trees so to speak

#include <SPI.h>   // Comes with Arduino IDE
#include "RF24.h"  // Download and Install (See above)
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // I2C LCD display
int buzzer = 2; //Buzzer pin
unsigned long timeoutmillis = 0;
//#define ENABLE_SERIAL // Enable only for debugging
// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x03F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
/*-----( Declare objects )-----*/
// (Create an instance of a radio, specifying the CE and CS pins. )
RF24 myRadio (7, 8); // "myRadio" is the identifier you will use in following methods
/*-----( Declare Variables )-----*/
byte addresses[][6] = {"1Node"}; // Create address for 1 pipe.
int dataReceived;  // Data that will be received from the transmitter
long previousMillis = 0; //buzzer timer ?
long interval = 3000; //3 seconds
int time_flag = 0; //Timer flag


void setup()   /****** SETUP: RUNS ONCE ******/
{
#ifdef ENABLE_SERIAL
  Serial.begin(57600);
  Serial.println("");
  Serial.println("=====================================");
  Serial.println("PIR sensor");
  Serial.println("=====================================");
#endif //#ifdef ENABLE_SERIAL
  pinMode(buzzer, OUTPUT);
  digitalWrite(buzzer, LOW);
  lcd.begin(8, 2);                             // Initialize the LCD.
  lcd.clear();
  delay(100);
  lcd.setCursor(0, 0);
  lcd.print("POWERING");
  lcd.setCursor(0, 1);
  lcd.print("  UP  ");// Print something on the display to show
  delay(100);
  myRadio.begin();  // Start up the physical nRF24L01 Radio
  myRadio.setChannel(108);  // Above most Wifi Channels
  // Set the PA Level low to prevent power supply related issues since this is a
  // getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
  //myRadio.setPALevel(RF24_PA_MIN); //uncomment for Low power
  myRadio.setPALevel(RF24_PA_MAX);  // Uncomment for more power
  myRadio.setDataRate(RF24_250KBPS); // Fast enough.. Better range
  myRadio.openReadingPipe(1, addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now)
  myRadio.startListening();
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  if ( myRadio.available()) // Check for incoming data from transmitter
  {
    while (myRadio.available())  // While there is data ready
    {
      myRadio.read( &dataReceived, sizeof(dataReceived) ); // Get the data payload (You must have defined that already!)
    }
    if (dataReceived == 12) {
      time_flag = 1;
    }
    if (time_flag == 1) {
      timeoutmillis = millis();
      if (timeoutmillis - previousMillis >= interval) {
        previousMillis = timeoutmillis;
        for (int i = 0; i < 100; i++) {
          digitalWrite(buzzer, HIGH);
        }
        time_flag = 0;
        delay(500);
        digitalWrite(buzzer, LOW);
        /* digitalWrite(buzzer, HIGH);
          delay(100);
          digitalWrite(buzzer, LOW);
          delay(100);
          digitalWrite(buzzer, HIGH);
          delay(100);
          digitalWrite(buzzer, LOW);
          delay(100);
          digitalWrite(buzzer, HIGH);
          delay(100);
          digitalWrite(buzzer, LOW);
          digitalWrite(buzzer, HIGH);
          delay(100);
          digitalWrite(buzzer, LOW);
          delay(100);
          digitalWrite(buzzer, HIGH);
          delay(100);
          digitalWrite(buzzer, LOW);
          delay(100);
          digitalWrite(buzzer, HIGH);
          delay(100);
          digitalWrite(buzzer, LOW);
          }
          }
          time_flag = 0;
          } //END Radio available
        */
      }
    }
  }
#ifdef ENABLE_SERIAL
  Serial.print("DATA: ");
  Serial.println(dataReceived, DEC);
#endif //#ifdef ENABLE_SERIAL
  lcd.setCursor(0, 0);
  lcd.print("DATA");
  lcd.setCursor(0, 1);
  lcd.print(dataReceived);
  lcd.print("V   ");

}//--(end main loop )---

Hopefully you can understand in what I’m trying to do, Any pointer idea’s would be great

        for (int i = 0; i < 100; i++)
        {
          digitalWrite(buzzer, HIGH);
        }

This for loop will execute in a small number of microseconds. Not what you want, I think. In addition, once the pin has gone HIGH it will remain HIGH whilst in the for loop.

Does the buzzer emit a tone when powered or does it need to be turned on and off to emit a tone ?

The buzzer needs to be turned on to make the sound, So to make it bleep I need to send the pin low and high to make the bleeping noise. I did try to send it high and low with the code that's highlighted out.

Well, it certainly will not work the way that you the for loop now. It will stay HIGH for a very small fraction of a second because of the for loop then stay HIGH for half a second because of teh delay() then go LOW. The most that you will hear is a slight single click.

What happened when you used the commented out code ?
Are you sure that the program ever executes the code in question ?
How about putting some Serial.print()s in there so that you know which code is being executed ?

I’ve done some more playing and got it working, I remembered when I first started Arduino and worked on a project(which never got finished). It jumped out of the loop for 25 seconds, So I messed about with it and it now works like I wanted it to, The down side is that while it’s in the triggered mode I can not do anything else which is not a bad thing, but the main thing is that I will be nofitied if the alarm has been trigged, I’ve got to tidy the code up.
May be there is a better way or method to use, but it’s working
thanks for the help
here is the code

#include <SPI.h>   // Comes with Arduino IDE
#include "RF24.h"  // Download and Install (See above)
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // I2C LCD display
int buzzer = 2; //Buzzer pin
unsigned long timeoutmillis = 0;
//#define ENABLE_SERIAL // Enable only for debugging
// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x03F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
/*-----( Declare objects )-----*/
// (Create an instance of a radio, specifying the CE and CS pins. )
RF24 myRadio (7, 8); // "myRadio" is the identifier you will use in following methods
/*-----( Declare Variables )-----*/
byte addresses[][6] = {"1Node"}; // Create address for 1 pipe.
int dataReceived;  // Data that will be received from the transmitter

int time_flag = 0; //Timer flag
unsigned long Liftdownstarted;
long Liftdowntime = 10000;
void setup()   /****** SETUP: RUNS ONCE ******/
{
#ifdef ENABLE_SERIAL
  Serial.begin(57600);
  Serial.println("");
  Serial.println("=====================================");
  Serial.println("PIR sensor");
  Serial.println("=====================================");
#endif //#ifdef ENABLE_SERIAL
  pinMode(buzzer, OUTPUT);
  digitalWrite(buzzer, LOW);
  lcd.begin(8, 2);                             // Initialize the LCD.
  lcd.clear();
  delay(100);
  lcd.setCursor(0, 0);
  lcd.print("POWERING");
  lcd.setCursor(0, 1);
  lcd.print("  UP  ");// Print something on the display to show
  delay(100);
  myRadio.begin();  // Start up the physical nRF24L01 Radio
  myRadio.setChannel(108);  // Above most Wifi Channels
  // Set the PA Level low to prevent power supply related issues since this is a
  // getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
  //myRadio.setPALevel(RF24_PA_MIN); //uncomment for Low power
  myRadio.setPALevel(RF24_PA_MAX);  // Uncomment for more power
  myRadio.setDataRate(RF24_250KBPS); // Fast enough.. Better range
  myRadio.openReadingPipe(1, addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now)
  myRadio.startListening();
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  if ( myRadio.available()) // Check for incoming data from transmitter
  {
    while (myRadio.available())  // While there is data ready
    {
      myRadio.read( &dataReceived, sizeof(dataReceived) ); // Get the data payload (You must have defined that already!)
    }
  }
  if (dataReceived == 12) {
    time_flag = 1;  //set the down falg to 1
    Liftdownstarted = millis();
    Alarm_status ();
  }
#ifdef ENABLE_SERIAL
  Serial.print("DATA: ");
  Serial.println(dataReceived, DEC);
#endif //#ifdef ENABLE_SERIAL
  lcd.setCursor(0, 0);
  lcd.print("DATA");
  lcd.setCursor(0, 1);
  lcd.print(dataReceived);
  lcd.print("V   ");

}//--(end main loop )---

void Alarm_status() {
  while (time_flag)  {
    digitalWrite(buzzer, HIGH);
    delay(150);
    digitalWrite(buzzer, LOW);
    delay(150);
    if ((time_flag == 1) && (millis() - Liftdownstarted >= Liftdowntime)) {
      if (time_flag == 1)
        delay(50);
      time_flag =  0;
      return;
    }
  }
}

The down side is that while it's in the triggered mode I can not do anything else

As long as you don't need to do anything else in this program that is OK but what if you wanted to cancel the alarm ? The delay() function is the culprit here.

Several things at the same time will provide insight into how to avoid the problem by using millis() for timing.

delay(...) is handy but not much else can happen while delay(...) is executing.
delay(100) wastes the considerable power of an Arduino for 1/10 of a second.
One hundred of delay(100) would waste the considerable power of an Arduino for 10 seconds.

Using millis() and a Finite State Machine (FSM), sometimes called a state machine for short, would be a better way.

This was only for testing, It's fine coming out the loop and the out of loop timer does you like blink with out delay it does not need to do anything else once triggered only to alert me, Just the HIGH and LOW that's got the delay for the time been, Will look into blink with delay.
The upgrade will have now blink with out delay for controlling the bleeper now that I got it working

thanks for the inputs