safwan092

Untitled

Apr 24th, 2022
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. int Sensor = 12;
  2. int LED = 13;
  3. int flg=0;
  4.  
  5. void setup() {
  6. Serial.begin(9600);
  7. pinMode (Sensor, INPUT);
  8. pinMode (LED, OUTPUT);
  9. Serial.println("Waiting for motion");
  10. }
  11.  
  12. void loop() {
  13. int val = digitalRead(Sensor); //Read Pin as input
  14. if((val > 0) && (flg==0))
  15. {
  16. digitalWrite(LED, HIGH);
  17. Serial.println("Motion Detected");
  18. flg = 1;
  19. }
  20. if(val == 0)
  21. {
  22. digitalWrite(LED, LOW);
  23. Serial.println("NO Motion");
  24. flg = 0;
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment