Advertisement
pleasedontcode

"Motion Detection" rev_01

Apr 27th, 2025
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Motion Detection"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-04-27 19:04:18
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Make the lights turn on and off in a wave pattern */
  21.     /* when motion is detected 2 times */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /* START CODE */
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31. void updateOutputs(void);
  32. void wavePattern(void); // Function to create wave pattern
  33.  
  34. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  35. const uint8_t idk_LED_PIN_D2 = 2;
  36. const int pirPin = 3;  
  37. const int LED1 = 13;
  38. const int LED2 = 11;
  39. const int LED3 = 9;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool idk_LED_PIN_D2_rawData = 0;
  44. bool motionDetected = false; // Added from USER CODE
  45. int motionCount = 0; // Count the number of motion detections
  46.  
  47. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  48. /***** used to store data after characteristic curve transformation *****/
  49. float idk_LED_PIN_D2_phyData = 0.0;
  50.  
  51. void setup(void)
  52. {
  53.     // put your setup code here, to run once:
  54.     pinMode(idk_LED_PIN_D2, OUTPUT);
  55.     pinMode(pirPin, INPUT); // Added from USER CODE
  56.     pinMode(LED1, OUTPUT); // Added from USER CODE
  57.     pinMode(LED2, OUTPUT); // Added from USER CODE
  58.     pinMode(LED3, OUTPUT); // Added from USER CODE
  59.     Serial.begin(9600); // Added from USER CODE
  60. }
  61.  
  62. void loop(void)
  63. {
  64.     // put your main code here, to run repeatedly:
  65.     updateOutputs(); // Refresh output data
  66.  
  67.     int motionState = digitalRead(pirPin); // Added from USER CODE
  68.  
  69.     if (motionState == HIGH) { // Added from USER CODE
  70.         motionCount++; // Increment motion count
  71.         Serial.println("Motion detected."); // Log motion detection
  72.  
  73.         if (motionCount == 2) { // Check if motion detected twice
  74.             wavePattern(); // Call wave pattern function
  75.             motionCount = 0; // Reset motion count after wave
  76.         }
  77.     } else { // Added from USER CODE
  78.         digitalWrite(LED1, LOW); // Added from USER CODE
  79.         digitalWrite(LED2, LOW); // Added from USER CODE
  80.         digitalWrite(LED3, LOW); // Added from USER CODE
  81.         Serial.println("Motion ended."); // Added from USER CODE
  82.     }
  83. }
  84.  
  85. void updateOutputs()
  86. {
  87.     digitalWrite(idk_LED_PIN_D2, idk_LED_PIN_D2_rawData);
  88. }
  89.  
  90. // Function to create wave pattern
  91. void wavePattern() {
  92.     digitalWrite(LED1, HIGH);
  93.     delay(100);
  94.     digitalWrite(LED1, LOW);
  95.    
  96.     digitalWrite(LED2, HIGH);
  97.     delay(100);
  98.     digitalWrite(LED2, LOW);
  99.    
  100.     digitalWrite(LED3, HIGH);
  101.     delay(100);
  102.     digitalWrite(LED3, LOW);
  103. }
  104.  
  105. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement