Skip to content

Instantly share code, notes, and snippets.

@handeyeco
Created April 18, 2020 16:42
Show Gist options
  • Save handeyeco/00487e78325fe00eee24ce60451e9ad1 to your computer and use it in GitHub Desktop.
Save handeyeco/00487e78325fe00eee24ce60451e9ad1 to your computer and use it in GitHub Desktop.
Arduino Audio Alarm
int relay = 2;
int input = 3;
int startBeep = 0;
int beepLength = 1000;
void setup() {
pinMode(relay, OUTPUT);
pinMode(input, INPUT);
Serial.begin(9600);
}
void loop() {
if (startBeep == 0) {
int reading = digitalRead(input);
if (reading == 1) {
Serial.println("Start Beep");
startBeep = millis();
digitalWrite(relay, HIGH);
delay(500);
}
} else {
int now = millis();
if (startBeep + beepLength < now) {
Serial.println("End Beep");
startBeep = 0;
digitalWrite(relay, LOW);
delay(500);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment