Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Arduino Dark Activated Motion Alarm
- *
- * learnelectronics
- * 12 SEPT 2017
- *
- * www.youtube.com/c/learnelectronics
- */
- #define ldr A0 //ldr is on pin A0 (voltage divider with 1.5k)
- #define pir 7 //pir is on pin 7
- #define alm 8 //active buzzer is on pin 8
- #define led 6 //armed indicator led is on pin 6
- int dark = 200; //darkness threshold - adjust to suit
- bool armed = 0; //0 if light, 1 if dark
- void setup() {
- pinMode(ldr,INPUT); //ldr set as input
- pinMode(pir,INPUT); //pir set as input
- pinMode(alm,OUTPUT); //buzzer set as output
- pinMode(led,OUTPUT); //led set as output
- //Serial.begin(9600);
- }
- void loop() {
- if (analogRead(ldr)<dark){ //if it's darker than the threshold
- armed = 1; //arm the system
- digitalWrite(led,HIGH); //turn on led
- }
- else{ //if it's not dark enough
- armed = 0; //disarm the sytem
- digitalWrite(led,LOW); //turn of the led
- }
- //Serial.println(analogRead(ldr)); //for debugging
- while (armed){ //if the system is armed
- if (digitalRead(pir) == 1){ //has the pir been triggered
- digitalWrite(alm,HIGH); //sound the alarm
- }
- else { //if the pir has not been triggered
- digitalWrite(alm,LOW); //silence the alarm
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement