Advertisement
ananias_hayes12

HOME ALARM SYSTEM FINAL

Jun 29th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd (12, 11, 10, 9, 15, 16);
  3. bool flag = false;
  4. const int photoPin = A0;
  5. const int piezoPin = 8;
  6. const int SER = 5; // serial output to shift register
  7. const int LATCH = 6; // shift register latch pin
  8. const int CLK = 7; //shift register clock pin
  9. const int motionPin = 13;
  10. int val = 0;
  11. int pirState = LOW;
  12. int motion = 0;
  13.  
  14. void setup()
  15. {
  16. pinMode (piezoPin, OUTPUT);
  17. pinMode (SER, OUTPUT);
  18. pinMode (LATCH, OUTPUT);
  19. pinMode (CLK, OUTPUT);
  20. digitalWrite (LATCH, LOW);
  21. shiftOut(SER, CLK, MSBFIRST, B00000000);
  22. digitalWrite (LATCH, HIGH);
  23. delay (500);
  24.  
  25. lcd.begin (16,2);
  26. lcd.print ( "Greetings" );
  27. lcd.setCursor (3,1);
  28. lcd.print ( "FAMILY");
  29. Serial.begin (9600);
  30. tone(piezoPin, 700);
  31. delay(30);
  32. noTone(piezoPin);
  33.  
  34.  
  35. }
  36.  
  37. void loop()
  38. {
  39. val = digitalRead(motionPin);
  40. if (val == HIGH)
  41. { // check if the input is HIGH
  42. digitalWrite (LATCH, LOW);
  43. shiftOut(SER, CLK, MSBFIRST, B11111111);
  44. digitalWrite (LATCH, HIGH);
  45. tone(piezoPin, 700);
  46. delay(500);
  47. noTone(piezoPin);
  48. lcd.clear();
  49. // we have just turned on
  50. lcd.println("Motion detected!");
  51.  
  52. delay (500);
  53. // We only want to print on the output change, not state
  54. pirState = HIGH;
  55.  
  56. }
  57. if (pirState == HIGH)
  58. {
  59. digitalWrite (LATCH, LOW);
  60. shiftOut(SER, CLK, MSBFIRST, B00000000);
  61. digitalWrite (LATCH, HIGH);
  62. lcd.clear();
  63. // we have just turned of
  64. lcd.println("Motion ended!");
  65. // We only want to print on the output change, not state
  66. pirState = LOW;
  67. delay (2000);
  68. }
  69.  
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement