-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Arduino Motion Sensor | ||
Created: 3/11/2015 | ||
By Gus | ||
Modified N/A | ||
By Gus | ||
http://pimylifeup.com/arduino-motion-sensor | ||
*/ | ||
|
||
|
||
int ledPin = 4; // Pin LED is connected to | ||
int piezoBuzzerPin = 3; // Pin Piezo Buzzer is connected to | ||
int pirSensorPin = 2; // PIN PIR Sensor is connected to | ||
|
||
int motionDetected = LOW; // Start MotionDetected as low (No motion detected) | ||
|
||
void setup() { | ||
pinMode(ledPin, OUTPUT); // declare LED as output | ||
pinMode(pirSensorPin, INPUT); // declare the PIR sensor as input | ||
pinMode(piezoBuzzerPin, OUTPUT); //declare buzzer as output | ||
Serial.begin(9600); //Set serial out if we want debugging | ||
delay(5000); //Allow time for the PIR Sensor to callibrate | ||
} | ||
|
||
void loop(){ | ||
motionDetected = digitalRead(pirSensorPin); // Read the PIR sensor | ||
if(motionDetected == HIGH) //If motion detected | ||
{ | ||
digitalWrite(ledPin, HIGH); | ||
analogWrite(piezoBuzzerPin, 200); | ||
delay(100); | ||
analogWrite(ledPin, LOW); | ||
analogWrite(piezoBuzzerPin, 25); | ||
delay(100); | ||
} | ||
digitalWrite(ledPin, LOW); | ||
digitalWrite(piezoBuzzerPin,LOW); | ||
} |