/*
Arduino | coding-help
Need help with alarm setup.
Harbinger July 7, 2025 — 9:37 AM
Hello all, thank you very much for reading.
I am working on a project to take the sound produced by a
buzzer from my NVR system by using a microphone sensor, then
i need the Arduino to activate a relay that will power
the 30 watt siren.
I have a separate power supply for the siren so it won't be
running off the Arduino.
I am more mechanically inclined and have been unable to find
the required code online.
I would truly appreciate some help with the required code.
Regards
*/
const unsigned long HOLD_TIME = 30; // seconds to stay on
const int SENSOR_PIN = 12;
const int RELAY_PIN = 11;
unsigned long triggeredTime = 0;
unsigned long holdTime = HOLD_TIME * 1000; // milliseconds to stay on
bool isTriggered = false;
void setup() {
Serial.begin(9600);
pinMode(SENSOR_PIN, INPUT);
pinMode(RELAY_PIN, OUTPUT);
}
void loop() {
int senseValue = digitalRead(SENSOR_PIN);
if (senseValue == LOW) { // or HIGH, depends on sensor
isTriggered = true;
triggeredTime = millis();
}
if (millis() - triggeredTime >= holdTime) {
isTriggered = false;
}
if (isTriggered) {
digitalWrite(RELAY_PIN, HIGH);
} else {
digitalWrite(RELAY_PIN, LOW);
}
}