/*** www.arduinopoint.com ***/
/*** Arduino with PIR Sensor LED and Buzzer ***/
int PIRSensor = 3; //Define PIR Sensor pin
int Buzzer = 4; //PWM (~) pin
int LED = 2; //Define LED pin
int SensorValue = 0; // Initializing the value as zero at the beginning
int pirState=LOW;
  
void setup() {
pinMode(Buzzer, OUTPUT);
pinMode(LED, OUTPUT);
pinMode(PIRSensor, INPUT);
Serial.begin(9600);
}

void loop() {
SensorValue = digitalRead(PIRSensor); // The value read from PIR Sensor pin 2 will be assigned to 'SensorValue'
if(SensorValue == HIGH)
{
  digitalWrite(LED, HIGH); // Turn LED ON
  if (pirState == LOW)
  {
  tone(Buzzer, 9000); //the buzzer sound frequency at 5000 Hz. The frequency range is from 31 Hz to 65535 Hz.
  Serial.println("Motion Detected"); // Print this text in Serial Monitor
  pirState=HIGH;
  }
}
else 
{
  digitalWrite(LED, LOW);
  if (pirState == HIGH)
  {
  noTone(Buzzer);
  Serial.println("Motion low Detected");
  pirState=LOW;
  }
}
}