Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **Intruder Alert**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-12-11 00:33:53
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Im working on a project where i use a PIR HC-SR501 */
- /* a led and a buzzer, the idea is that the PIR */
- /* detects movement and the buzzer with the led turn */
- /* on for 2 seconds , after that I need the PIR to */
- /* identify movement again but instantly */
- /****** END SYSTEM REQUIREMENTS *****/
- /********* User code review feedback **********
- #### Feedback 1 ####
- - The light and buzzer sounds like 60 seconds remember it has to s
- topped after 3 seconds, and when the buzzer and led turns off af
- ter those 3 seconds it has to start reading movement again after
- it finish
- ********* User code review feedback **********/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // USER CODE
- int pir_pin = 2;
- int led_pin = 3;
- int buzzer_pin = 4;
- unsigned long start_time = 0; // Variable to store the start time
- bool intruder_detected = false; // Intruder detection state
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(pir_pin, INPUT);
- pinMode(led_pin, OUTPUT);
- pinMode(buzzer_pin, OUTPUT);
- Serial.begin(9600);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- if (digitalRead(pir_pin) == HIGH)
- {
- if (!intruder_detected) // Only activate if not previously detected
- {
- intruder_detected = true;
- start_time = millis(); // Record the start time
- digitalWrite(led_pin, HIGH);
- digitalWrite(buzzer_pin, HIGH);
- Serial.println("Intruder detected");
- }
- // Turn off the buzzer and LED after 3 seconds
- if (millis() - start_time >= 3000)
- {
- digitalWrite(buzzer_pin, LOW);
- digitalWrite(led_pin, LOW);
- intruder_detected = false; // Reset the state to allow for immediate detection again
- Serial.println("Monitoring resumed");
- }
- }
- else
- {
- // If no intruder is detected, keep the LED and buzzer off
- digitalWrite(led_pin, LOW);
- digitalWrite(buzzer_pin, LOW);
- Serial.println("Monitoring");
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement