Simple Arduino Alarm System Using PIR sensor

EEE Arduino projects 


Finishing an Arduino venture gives you a feeling of fulfilment like no other. The issue is, most apprentices aren't sure where to begin, and without past Creator experience, or some kind of gadgets foundation, much fledgeling's undertakings can appear to be fair… well, overwhelming.

Simple Arduino Alarm System Using PIR sensor

simple steps flow to make an alarm system


Step 1Gather your parts.
Step 2: Wire the Arduino to the breadboard. 
Step 3: Connect your motion sensor. 
Step 4: Plug in the LED. 
Step 5Connect the piezo buzzer. 
Step 6: Program the Arduino. 
Step 7Test your alarm


Step 1 :required parts
   
       

 piezo buzzer                                     beradboard                                      leds



                                                     PIR sensor




     
Circuit diagram

code explanation


                            initialised pins which are required


set the pin mode initially what condition you required like input OR output



loop for control operation





 copy this Arduino code  


//////This code upload by www.eeeprojectideas.blogspot.com /////// 

//////intalised commands it is delard by  example   int a=12  //////


int ledPin = 13;                // choose the pin for the LED

int inputPin = 2;               // choose the input pin (for PIR sensor)
int PIRState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
int pinSpeaker = 10;           //Set up a speaker on a PWM pin (digital 9, 10, or 11)

\\\where pinmode used to set it is i/p or o/p mode////
\\\\serial used serial board where ardunio range 9600//////
void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
  pinMode(pinSpeaker, OUTPUT);
  Serial.begin(9600);
}

void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    playTone(300, 160);
    delay(150);

    
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
      digitalWrite(ledPin, LOW); // turn LED OFF
      playTone(0, 0);
      delay(300);    
      if (pirState == HIGH){
      // we have just turned off
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      // Inside Of The Serial Port
      pirState = LOW;
    }
  }
}

// Tell Arduino To Play Piezo Buzzer Tone
// duration in msec, frequency in hertz

void playTone(long duration, int freq) {
    duration *= 1000;
    int period = (1.0 / freq) * 1000000;
    long elapsed_time = 0;
    while (elapsed_time < duration) {
        digitalWrite(pinSpeaker,HIGH);
        delayMicroseconds(period / 2);
        digitalWrite(pinSpeaker, LOW);
        delayMicroseconds(period / 2);
        elapsed_time += (period);
    }
}

Comments

Unknown said…
nice code explantion

Popular posts from this blog

LIFE CYCLE TESTING OF ELECTRICAL LOADS BY DOWN COUNTER

BLDC MOTOR SPEED CONTROL WITH RPM DISPLAY

LIFE CYCLE TESTING OF ELECTRICAL LOADS BY DOWN COUNTER