Skip to content

Commit

Permalink
add source for PIR sensor buzzer project12
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardChambers committed Jan 30, 2018
1 parent ce3ad90 commit e8e9a97
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions project12/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

pirbuzzer: pirbuzzer.c
cc -o pirbuzzer pirbuzzer.c -lwiringPi
35 changes: 35 additions & 0 deletions project12/pirbuzzer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

#include <stdio.h>
#include <wiringPi.h>

int main (void)
{
const int BuzzerPin = 1; // buzzer is attached Pin #1 or BCM #18
const int PirSensorPin = 0; // PIR sensor is attached Pin #0 or BCM #17
int alarmState; // current alarm state to reduce output lines.

if (wiringPiSetup() == -1) {
printf ("setup of wiringPi lib failed.\n");
return 1;
}

pinMode (BuzzerPin, OUTPUT);
pinMode (PirSensorPin, INPUT);

alarmState = 0;
printf (" -- No alarm\n");
while (1) {
if (digitalRead (PirSensorPin) == 0) {
digitalWrite (BuzzerPin, HIGH);
alarmState == 1 && printf (" -- No alarm\n");
alarmState = 0;
} else {
digitalWrite (BuzzerPin, LOW);
alarmState == 0 && printf ("*** Alarm!\n");
alarmState = 1;
}
delay(1000);
}

return 0;
}

0 comments on commit e8e9a97

Please sign in to comment.