I am doing a project on accident detection, so when a sensor detects vibration, the buzzer is on, and the Arduino waits for 30 secs, for the driver to press a switch. If the driver doesn't press the switch, a message is sent.
I want to know how the Arduino will wait for 30 secs. It won't work with delay.
Give me suggestions.
I want to know how the Arduino will wait for 30 secs.
If I call you, and invite you to meet me at the pub for a drink in 30 minutes, how will you arrive at the pub at the right time? Will you set a timer for 30 minutes, and do nothing but stare at it for 30 minutes? That is what delay does.
The alternative is to note what time it is now, and, periodically, see if 30 minutes has elapsed. THAT is the approach that the blink without delay example illustrates.
But the user can press that switch at any time so how should I use the delay.
If I use the delay before the switch program and user has already pressed the switch it won't detect. So how and where should I use delay?
Anket:
So how and where should I use delay?
PaulS's point is clearly that you mustn't use delay, but rather use the Blink without Delay approach.
Is there any other way rather than using blink without delay?
I think 'blink without delay' approach is the best way to solve it. Is there any issue in applying 'without delay' approach?
I don't know how to use it with a swich button, so if u people can explain it to me in simple way, it would be a great help for me..
And thanks for your comments.
I would say first you understand the 'Blink without delay' code and run it and see how it works, then add a button and read the state using 'digitalRead'
Then post your code if it's not working, so some one can help you fix it.
Anket:
Is there any other way rather than using blink without delay?
You sort of answered that yourself: you already know it doesn't work with delay, since it's not looking at the button in a delay(), so without delay is the way to go.
As sarouje says, at least start by getting your mind round the Blink without Delay (ie millis()) approach.