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