Go Down

Topic: Start a buzzer after an input is now for a specific amount of time (Read 70 times) previous topic - next topic

spawn2qc

Hello,

I have a stupid cat going to the pantry pushing his food box on the ground and eating it.

I have to lock the pantry... (or sell the cat but gf doesn't like the idea)

Sometimes, we forgot to lock it and I want to know it.

I would like to use a switch telling me the pantry is lock or not.

If the switch if OFF for let's say 30 seconds, I want a buzzer telling me I am the stupid one.

I went through many arduino timers examples, but can't find what I need.

  • Timer goes on when switch goes off
  • Timer goes off when switch on
  • Output set to HIGH when timer overflow
I am new to timer and I would really appreciate if someone can help me with an example or guide me to a good tutorial.

Best regards,
Hugo

BertTheAvenger

It doesn't seem like you need to use a timer for this. Consider storing the time the switch first turns off with millis(), intermittently check if the switch has been closed, and if time elapses 30sec ex.(millis() - lastMillisOpened > 30000), sound the buzzer.


For a more advanced approach, look at interrupts.

outsider

Do you need to know if the door is just closed or closed AND locked? If the latter, what kind of switch will you use on the lock?

UKHeliBob

Quote
Timer goes on when switch goes off
Timer goes off when switch on
Output set to HIGH when timer overflow
The key to this is to detect when the switch becomes off, not when it is off.

If the switch becomes off save the value of millis() as the start value and set a boolean to true
If the switch becomes on set the boolean to false
Every time through loop() if the boolean is true (timing is occuring) check whether the current value of millis() minus the start value is greater than the required period.  If so then sound the alarm/flash a light/whatever
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

spawn2qc

Hello,

Thank you Bert for the millis() idea.

I will definitely take a look at it later.

I need to know only if it is locked or not since I can't lock it when doors are open.

Outsider, this is a "Safety 1st" baby lock and I want to add contacts to it.

Bob, I understand what you mean, else stored value and millis would be the same.

I need to detect rising/falling edges.

Best regards,
Hugo

UKHeliBob

Quote
I need to detect rising/falling edges.
The StateChangeDetecion example in the IDE will show you how if you are not already familiar with the principle
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up