BOMB Detector – week5

I use PIR motion sensor with Piezo buzzer, this device will attach with ankle to detect how people move. If people move or walk, it will make noise so you know something moving. Another concept is detect how fast or slow when people are walking, when they walk fast the sound will continue beeping and when they walk slow they sound will stop. New yorkers are walking very fast and ignore other people and surrounding. So this will help them to walk slow and give more attention to what ever surround them.

 

IMG_0627IMG_0628

int ledPin = 13;
int inputPin = 2;
int pirState = LOW;
int val = 0;
int pinSpeaker = 10;
void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(inputPin, INPUT);
  pinMode(pinSpeaker, OUTPUT);
  Serial.begin(9600);
}
void loop(){
  val = digitalRead(inputPin);
  if (val == HIGH) {
    digitalWrite(ledPin, HIGH);
    playTone(300, 160);
    delay(1500);
    if (pirState == LOW) {
      Serial.println(“Motion detected!”);
      pirState = HIGH;
    }
  } else {
      digitalWrite(ledPin, LOW);
      playTone(0, 0);
      delay(1500);
      if (pirState == HIGH){
      Serial.println(“Motion ended!”);
      pirState = LOW;
    }
  }
}
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 / 4);
        digitalWrite(pinSpeaker, LOW);
        delayMicroseconds(period / 8);
        elapsed_time += (period/2);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *