/*
Name: HW12_PASSIVE_INFRARED_RECEIVER__PIR____blizard.ino
Created: 11/25/2022 6:55:04 PM
Author: nblizard
Problem statement:
Passive Infrared Receiver (PIR) Sensor:
The PIR sensor is a very simple device to use. There is a 3 pin connection for VCC, OUT, and GND. T
he VCC and GND should be connected to 5 volts and ground respectively. T
he OUT pin should connect to any of the digital input pins on the arduino.
When the PIR sensor detects motion the OUT pin will go HIGH.
There are two potentiometers on your PIR sensor that can be used to adjust the sensitivity
and the length of time that the OUT pin stays high when motion is detected.
Create a simple motion alarm. Use the Piezo speaker to sound an alarm when motion is detected,
sound the alarm for 10 seconds after motion is detected.
*/
#include <NewTone.h>
const byte BUZZER_PIN = 5;
const byte PIR_DATA_PIN = 8;
const bool CLOSE = HIGH;
const bool FAR = !CLOSE;
const int TIME_TO_BUZZ = 10000; // 10 seconds
const int FREQ = 1000; //1kHz
// the setup function runs once when you press reset or power the board
void setup() {
pinMode(BUZZER_PIN, OUTPUT);
pinMode(PIR_DATA_PIN, INPUT);
}
// the loop function runs over and over again until power down or reset
void loop() {
if (digitalRead(PIR_DATA_PIN) == CLOSE) {
//tone(BUZZER_PIN, TIME_TO_BUZZ);
NewTone(BUZZER_PIN, FREQ);
delay (TIME_TO_BUZZ);
}
else {
//noTone(BUZZER_PIN);
noNewTone(BUZZER_PIN);
}
}