PIR Motion Sensor with Piezo Buzzer and LEDs

I am trying to program a PIR motion sensor that will sense motion and turn on a piezo buzzer and LED light that are all connected on a Parallax Propeller. The code is written in C and used on Simple IDE. The code works to where the motion is sensed and turns on the buzzer and LED but I can't turn it off unless I unplug the circuit. I was thinking of adding a push button that will turn it off and reset it to the previous state. Any advice?
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* SERIAL_TERMINAL USED */


// ------ Libraries and Definitions ------
#include "simpletools.h"

// ------ Global Variables and Objects ------
int pir;

// ------ Function Declarations ------
void led2();

// ------ Main Program ------
int main() {

  // Wait 20 to 30 seconds for  PIR to calibrate or"warm up"
  print("Wait about 20 seconds for PIR to calibrate...........");
  print("\r");
  pause(20000);
  term_cmd(CLS);
  // Once the PIR detects movement, it will send a HIGH or  a value of 1 out from its OUTPUT pin
  while (1) {
    pir = input(5);
    if (pir == 1) {
      cog_run(led2, 128);
      while (1) {
        print("Intruder Alert!");
        print("\r");
        freqout(4, 500, 1000);
        term_cmd(CLS);
        pause(1000);
      }
    }

  }

}

// ------ Functions ------
void led2() {
  while (1) {
    high(2);
    pause(500);
    low(2);
    pause(500);
  }
  return 0;
}
// 
Last edited on
Please edit your post for readability
https://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.