weinerm21

Untitled

Jun 28th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. int ledPin = 12; // choose the pin for the LED
  2. int inputPin = 2; // choose the input pin (for PIR sensor)
  3. int pirState = LOW; // we start, assuming no motion detected
  4. int val = 0; // variable for reading the pin status
  5. const int coil1 = 9;
  6. const int coil2 = 6;
  7. const int coil3 = 3;
  8. const int coil4 = 5;
  9.  
  10. void setup()
  11. {
  12. pinMode(ledPin, OUTPUT); // declare LED as output
  13. pinMode(inputPin, INPUT); // declare sensor as input
  14. pinMode(coil1, OUTPUT);
  15. pinMode(coil2, OUTPUT);
  16. pinMode(coil3, OUTPUT);
  17. pinMode(coil4, OUTPUT);
  18. Serial.begin(9600);
  19. }
  20.  
  21. void loop()
  22. {
  23. val = digitalRead(inputPin); // read input value
  24. if (val == HIGH) { // check if the input is HIGH
  25. digitalWrite(ledPin, HIGH); // turn LED ON
  26. if (pirState == LOW) {
  27. // we have just turned on
  28. Serial.println("Motion detected!");
  29. // We only want to print on the output change, not state
  30. pirState = HIGH;
  31. }
  32. } else {
  33. digitalWrite(ledPin, LOW); // turn LED OFF
  34. if (pirState == HIGH){
  35. // we have just turned of
  36. Serial.println("Motion ended!");
  37. // We only want to print on the output change, not state
  38. pirState = LOW;
  39. }
  40. }
  41. {
  42. // put your main code here, to run repeatedly:
  43. digitalWrite(coil4, LOW);
  44. digitalWrite(coil2, HIGH);
  45. delayMicroseconds(1600);
  46.  
  47. digitalWrite(coil1, LOW);
  48. digitalWrite(coil3, HIGH);
  49. delayMicroseconds(1600);
  50.  
  51. digitalWrite(coil2, LOW);
  52. digitalWrite(coil4, HIGH);
  53. delayMicroseconds(1600);
  54.  
  55. digitalWrite(coil3, LOW);
  56. digitalWrite(coil1, HIGH);
  57. delayMicroseconds(1600);
  58. }
  59. }
Add Comment
Please, Sign In to add comment