//The IoT Projects: https://theiotprojects.com
//Attiny85 Intruder Security Alarm using Viabration Sensor
// Using Digispark ATTINY85
int Buzz = 3; //Buzzer
int LED = 1; //LED
int vs =2; // vibration sensor
int vib = digitalRead(vs);
if(vib == HIGH)
Everything is working great but I need help adding something to do it.
The alarm sounds every time vibration is detected. Now what I want to do is:
When vibration detected, sound alarm twice (as the code currently does) as a warning, then if the warning alarm is activated X number of times within 30 seconds then sound the main alarm, ie: Alarm sounds forever
But I'm new to coding and I can't figure out how I would:
Start timer on first alarm activation
Count the number of times alarm is activated
If alarm has been activated X number of times within 30 seconds then keep alarm sounding forever
If alarm hasn't been activated X number of times within 30 seconds, reset timer and activation count.
Can someone help me please?
I think I just need an example so I can get my head around how it works.
If counting is not taking place (a boolean is false) and the alarm becomes activated then save the value of millis(), set the boolean to true to flag that counting is taking place, set a counter variable to zero and sound the warning
If counting is taking place and the alarm becomes activated increment the counter
If counting is taking place, millis() now minus start millis() previously saved is equal to or greater than 30 seconds and the counter is greater than the trigger number then sound the alarm continuously
If counting is taking place, millis() now minus start millis() previously saved is equal to 30 seconds and the counter is less than the trigger number then turn off counting