Here is the original code:
int ledpin = 13; //activates arduino light when there's a detection
int ledpin2 = 11; //activates external LED or buzzer when there's a detection
int outputpin = 3; //pin the relay control is attached to
int sensorpin = 12; //pin the detector is attached to
int warnpin = 4; //pin used to activate warning LED or buzzer
int counter = 0; //countdown since last detection
int counter2 = 0; //countdown since last non-detection
//change the next 2 settings to adjust the timer intervals
int countmax = 10000; //maximum level of countdown timer. 1000 = 1 second
int countwarn = 2000; //when to turn on warning pin. 1000 = 1 second
void setup() {
pinMode(ledpin, OUTPUT);
pinMode(ledpin2, OUTPUT);
pinMode(outputpin, OUTPUT);
pinMode(warnpin, OUTPUT);
pinMode(sensorpin, INPUT);
counter = countmax;
counter2 = countmax;
//any line with "serial" is for debugging and should be commented out if not needed because it will slow the clock down
//Serial.begin(9600);
//Serial.print("count: ");
//Serial.println(counter);
//Serial.print("count2: ");
//Serial.println(counter2);
}
void loop() {
if (digitalRead(sensorpin)) //what to do when there is a non-detection
{
digitalWrite(ledpin, LOW);
digitalWrite(ledpin2, LOW);
counter = counter - 10;
counter2 = countmax;
} else //what to do when there is a detection
{
digitalWrite(ledpin, HIGH);
digitalWrite(ledpin2, HIGH);
counter = countmax;
counter2 = counter2 - 10;
}
//serial output lines for debugging
//Serial.print("count: ");
//Serial.println(counter);
//Serial.print("count2: ");
//Serial.println(counter2);
//Serial.println("-----------");
//sound a warning if either counter is above 0 but under the "countwarn" level
if (counter > 0 && counter < countwarn || counter2 > 0 && counter2 < countwarn) {
digitalWrite(warnpin, HIGH);
} else {
digitalWrite(warnpin, LOW);
}
//turn off the output if either counter drops below 0
//these settings are for an "active low" relay. Switch "HIGH" and LOW for an active high output
if (counter < 0) {
digitalWrite(outputpin, HIGH);
counter = 0;
} else if (counter2 < 0) {
digitalWrite(outputpin, HIGH);
counter2 = 0;
} else {
digitalWrite(outputpin, LOW);
}
delay(10); // wait time (miliseconds) before going again
}
If you simply do not connect an external LED or buzzer, the code will do exactly what you want - just turn on/off depending on the detector.