Holding Button down for 3 seconds to shut off device.

Discussion in 'The Projects Forum' started by Paul81, Feb 16, 2013.

  1. Paul81

    Thread Starter New Member

    Dec 19, 2012
    8
    0
    I would liek to know how I would be able to shut down my project I am working on with a tact switch. Just like an android phone where you have to hold down the power button down for a couple seconds to shut down the phone.

    Would I have to look into battery management IC's or would I have to look more into the microprocessors aspect.
     
  2. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Need a bit more info.

    One push gives one function, while a long press gives a different function.

    The functions do not have to be power control, the short/long can be for scrolling/selecting menu items.

    These functions are typically accomplished with microcontrollers, or microprocessors in the case of Android.

    When the button is pressed, the system is alerted, it waits a while (Humans are terribly slow compared to the speed uCs run), and checks to see if the button has been released. If it has, the first function is called. If it hasn't, it times how long the button has been pressed prior to release, if it is the window (e.g. not stuck down), then the second function is called.

    The way to do this with least overhead is with interrupts, otherwise the system will slow down/lock up while waiting for the button to be released.

    Adding switch debouncing code to the routine does complicate it a bit, though the same general principle is applied.
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    In this project for a switch timer I used a single button to start the timer, stop the timer, enter a program mode, and change the program preset time. A speaker that beeps or boops (two tones, either short or long) works as feedback to tell the user what is happening.

    User feedback was very positive... hey it's just a timer but making it easy and intuitive to use was the overriding goal.

    Oh, it uses a micro, of course. The switch and the micro work together to enable a regulator so "off" is not very low power but is zero power.
     
  4. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    I've done this with a small hand-held device.

    If the processor has a low-power sleep mode, you can leave it powered all the time. Then all you need to do is to switch it in or out of sleep mode when the pushbutton is pressed, or pressed for some period of time etc. If you actually need to turn power on and off, that gets a lot more interesting, but it can also be done if you need to.
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    I never caught that project when it was active. Nice Work!

    Is it still holding up?
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    Thanks. It went under salt water for a week after Sandy, so my plans are to just rebuild it.
     
  7. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Project to keep room from flooding by pumping too much is flooded by Mother Nature. Ironic.
     
Loading...