Hi all, I'm a complete newbie to Arduino but am having a blast experimenting with it. I'm trying to create a simple alarm system whereby an LED lights whenever a PIR sensor detects motion. I'm able to get the LED to light when motion is detected, however, I want to make it so the LED continues to be lit (blinks continuously) until a pushbutton is depressed as a reset.
For the life of me, I can figure out the code to keep the LED blinking until a reset via pushbutton... it blinks for a few seconds and then turns off until new motion is detected... any help would be greatly appreciated! Thanks!
My code so far:
*/
const byte alarmLED = 9; // LED pin for INTRUDER DETECTED!!! (blink)
const byte safeLED = 13; // LED pin for SAFE (steady)
const byte motionPin = 2; // motion detector input pin
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
int resetButton = 7; // the Reset Button pin
byte senseMotion = 0; // variable to hold current state of motion detector
void setup() {
// set the digital pin directions
pinMode(alarmLED, OUTPUT);
pinMode(safeLED, OUTPUT);
pinMode(motionPin, INPUT);
pinMode(resetButton, INPUT);
}
void loop()
{
// Now watch for burglers
senseMotion = digitalRead(motionPin);
if (senseMotion == HIGH)
{
// burgler found!
analogWrite(alarmLED, brightness); // set the brightness for ledPin
digitalWrite(safeLED, LOW); // turns off LED2 when motion is sensed
brightness = brightness + fadeAmount; // change the brightness for next time through the loop
if (brightness == 0 || brightness == 255) // reverse the direction of the fading at the ends of the fade
{
fadeAmount = -fadeAmount;
}
delay (10); // (set how fast it fades) wait for X milliseconds to see the dimming effect
}
// Need to hold the blinking until a Reset is detected
else
{ // no burgler, yet...
digitalWrite(alarmLED, LOW); // turns off LED1 if motion is not sensed
digitalWrite(safeLED, HIGH); // turns on LED2 when NO motion
}
}