fork download
  1. int Sinput = A1; // Sensor input signal pin (A1)
  2. int Buz = 3; // Buzzer output pin (digital pin 3)
  3.  
  4. unsigned long previousMillis = 0; // Store the last time the buzzer was triggered
  5. const long interval = 2000; // 2 seconds delay for the buzzer
  6.  
  7. void setup() {
  8. pinMode(Sinput, INPUT); // Set sensor pin as input
  9. pinMode(Buz, OUTPUT); // Set buzzer pin as output
  10. }
  11.  
  12. void loop() {
  13. unsigned long currentMillis = millis(); // Get current time
  14.  
  15. // Check if the sensor input is LOW (inactive state)
  16. if(digitalRead(Sinput) == LOW) {
  17. // If 2 seconds have passed since the last buzzer trigger, turn it on
  18. if(currentMillis - previousMillis >= interval) {
  19. digitalWrite(Buz, HIGH); // Turn on buzzer
  20. }
  21. } else {
  22. // If the sensor input is HIGH (active state), turn off the buzzer
  23. digitalWrite(Buz, LOW); // Turn off buzzer
  24. }
  25. }
  26.  
Success #stdin #stdout 0.02s 25964KB
stdin
Standard input is empty
stdout
int Sinput = A1;    // Sensor input signal pin (A1)
int Buz = 3;         // Buzzer output pin (digital pin 3)

unsigned long previousMillis = 0;  // Store the last time the buzzer was triggered
const long interval = 2000;        // 2 seconds delay for the buzzer

void setup() {  
  pinMode(Sinput, INPUT);  // Set sensor pin as input
  pinMode(Buz, OUTPUT);    // Set buzzer pin as output
}

void loop() {
  unsigned long currentMillis = millis();  // Get current time

  // Check if the sensor input is LOW (inactive state)
  if(digitalRead(Sinput) == LOW) {
    // If 2 seconds have passed since the last buzzer trigger, turn it on
    if(currentMillis - previousMillis >= interval) {
      digitalWrite(Buz, HIGH); // Turn on buzzer
    }
  } else {
    // If the sensor input is HIGH (active state), turn off the buzzer
    digitalWrite(Buz, LOW);  // Turn off buzzer
  }
}