# if condition is satisfied for 15 min then send message

I am using vibration sensor and GSM modem with arduino mega in my project. My problem is if vibration value is greater than 500 for 15 min then I have to send message through GSM modem. How to do it?

rohitbhoi0707: I am using vibration sensor and GSM modem with arduino mega in my project. My problem is if vibration value is greater than 500 for 15 min then I have to send message through GSM modem. How to do it?

What does your sensor data look like? Does it give you an average, or fluctuating values? Did you think about that?

fluctuating value.... if vibration is large then its greater than 500 or else less. e.g 500 300 596 74 52 63 665 . .....

So does it ever stay above 500 for extended periods of time, such as 15 minutes? In other words, should a single low value restart the timer? Have you gathered sample data from your actual application?

The problem is, a transducer such as an inertial microphone, produces an output that tracks the actual excursions of the source. There are always moments when the source is not moving, such as when it changes direction. These values will appear as zeroes in the transducer output. So your timer will expire almost instantly.

lets say its during operation if value goes above 500 and its stay 500 or above for 15 min its should send sms and if values go down then it should stop timer

Is this hypothetical, or have you actually seen a data stream from the sensor?

The basic approach is to save a time stamp every time the value is less than 500. If the time now is ever more than 15 minutes greater than that stamp, send an SMS.

rohitbhoi0707: lets say its during operation if value goes above 500 and its stay 500 or above for 15 min its should send sms and if values go down then it should stop timer

Note when the value changes from below 500 to above 500. When that happens, record the time using millis(). Note when the value changes from above 500 to below 500. When that happens, clear the time.

Periodically, see if now minus then (when the value went above 500) is greater than 15 minutes. If it is, do something.

Not exactly rocket science.

The blink with delay and state change detection examples have everything you need.

``````static unsigned long startTime = 0;