Execute function for certain time

Update: the sprayer does not need to spray after the toilet is cleaned (door remains open during cleaning). And there is a manual button in the Arduino which triggers an interrupt and then sprays manually.

Post the rest of your code.

millis() does not advance in an interrupt routine.

So that’s at least a part of your problem.

a7

1 Like

I would recommend putting some Serial.println statements in the code so you can track the sequence of events and control logic

You are over-engineering the problem. A 555 timer triggered by the water flush actuator (whatever style it is) is enough. Since cleaning the toilet as opposed to using it is the exception, make a temporary killer switch that will exclude the firing circuit for the time it takes to do the cleaning. Or just disconnect it by hand: it's not the end of the world if you forget to restore it when the cleaning is over and the "air freshener" doesn't fire next time, is it?

P.S. Maybe it's not my business, but the proper way to deal with unpleasant odours in the bathroom is forced ventilation (which you can automate), not chemical concoctions that let that other smell through anyway and just give you headaches on top of that (ask me how I know). By the way, 15 seconds of uninterrupted spray seems like an eternity to me: I'd run for my life before half that time is over, I'm afraid.

You do not need an interrupt for this. The way you have the code written you have multiple issues with the interrupt. As @alto777 stated millis () does not advance in an interrupt routine. Additionally, spraysLeft would need to be defined with the volatile keyword and reading and writing of that variable would need to be done in loop() with interrupts disabled because it is a multi-byte variable.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.