Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. /*
  2. * PIR sensor tester
  3. */
  4.  
  5. #include <Servo.h>
  6. #define TURN_TIME 1000
  7.  
  8. int inputPin = 2; // choose the input pin (for PIR sensor)
  9. int pirState = LOW; // we start, assuming no motion detected
  10. int val = 0; // variable for reading the pin status
  11.  
  12. Servo myservo;
  13.  
  14. void setup()
  15. {
  16. pinMode(inputPin, INPUT); // declare sensor as input
  17. Serial.begin(9600);
  18. myservo.attach(9);
  19. myservo.write(90);
  20. }
  21.  
  22. void loop()
  23. {
  24. val = digitalRead(inputPin); // read input value
  25.  
  26. if (val == HIGH) { // check if the input is HIGH
  27. myservo.write(0);
  28. delay(TURN_TIME);
  29. myservo.write(90);
  30. delay(5000); //delays 5 seconds then returns to starting point
  31. myservo.write(180);
  32. delay(TURN_TIME);
  33. myservo.write(90);
  34. }
  35. else
  36. {
  37. myservo.write(90);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement