if(beep) then delay(500) if(!beep)then delay(500) if(beep) then fire=true;but that doesnt works 100%. It may take from a few seconds up to a minute until the Arduino gets it.
A typical US smoke alarm beeps for two reasons: it's detected smoke, and its battery is failing. When the battery starts to fail, the alarm emits very short beeps with a fairly long delay between them. These detectors don't have a mode in which they beep in some other pattern, for some sizeable fraction of the time, to tell you about something other than smoke. I don't think there's any necessity to check for a specific beep pattern - only that there's plenty of beeping.If this is how your detector behaves, I'd suggest looking for a period in which beeping persists more than some reasonable percentage of the time, or something like that. If it's beeping very much, then it's in alarm.
I assume you have a "microphone board" or something to pick-up the sound?A couple of problems... That's not going to do anything unless "beep" is defined somewhere.You don't want any delays,* because the program pauses during the delay and it can't do anything. Imagine you were using a stopwatch, you wouldn't pause/stop the stopwatch when you're trying to measure the time.You need run the processor continuously and measure the duration of the beep (and the duration of the silence).Start by simply doing that... First, make sure you can detect the beep... Maybe turn the LED on when you sense the beep. Then save the millis() time when the beep starts, and save the millis() time when the beep stops. Subtract to find the time.Then, you can work on the main logic for your code (if-statements, etc.). Be sure to give yourself some tolerance. It may not be exactly 500mS so maybe look for a duration of 450-550mS, etc.* delay() is used rarely in real-world programs except occasionally for very-short delays or when you are sure it's OK for the processing to pause.
Here is similar project:http://www.instructables.com/id/Secret-Knock-Detecting-Door-Lock/May be you can use a piezo as a sensor, and completely replicate a project?