I have a project of a pill dispenser and I would like to activate the mechanism to let the pills fall down with a button.

After being pressed I would like to deactivate the possibility to press again the button in order not to activate the mechanism twice.

Anyone has an idea of how to do it?

  • Add a state variable. – Juraj Oct 22 '18 at 11:45
  • Add a delay() after the pills have been released and the dispenser closed. This will also act as a natural debounce of the button. – Mikael Patel Oct 22 '18 at 13:53
  • 3
    It's no more off-topic than many similar new-user questions about coding techniques, is applicable to Arduino, helps a new user to learn, and is readily answerable, as the suggestions above show. Voting to re-open. – JRobert Oct 22 '18 at 15:40
  • 2
    use a flag variable .... in setup() add line bool dispense = true; ...... after you detect a button press, check the value of dispense .... if it is True then run the dispenser and set the flag to False so that no more dispenses will occur .... if (dispense) { run dispenser; dispense = false;} – jsotola Oct 22 '18 at 16:31

Browse other questions tagged or ask your own question.