Push Button Long press On/Off dual function

Discussion in 'Digital Circuit Design' started by Udhaya Prakash Jayaram, Jan 5, 2017.

  1. Udhaya Prakash Jayaram

    Thread Starter New Member

    Dec 24, 2015
    3
    0
    I need circuit to ON/OFF led when push button is long pressed(2 to 5 sec) without micro-controller or programming. Required any kind of simple circuits, can anyone help me?
     
  2. crutschow

    Expert

    Mar 14, 2008
    23,096
    6,850
    Here's the LTspice simulation of a circuit that should do what you want.

    D2 is your LED.

    The CD4013 is two flip-flops in one package. You must add power and ground to that chip (not shown).

    The delay time is determined by the value of R1 and C1.
    The values shown give a delay of about 3.5s.

    upload_2017-1-5_10-14-56.png
     
  3. Udhaya Prakash Jayaram

    Thread Starter New Member

    Dec 24, 2015
    3
    0
    thanks for your response I have tried to implement this circuit using proteus simulation but i cant able to find this part can you help me ? upload_2017-1-6_22-24-26.png
     
  4. crutschow

    Expert

    Mar 14, 2008
    23,096
    6,850
    SW is just a voltage-controlled switch or relay to simulate a push-button.
    Here's a reference for that.
    V2 and V3 control the switch closure.
     
    Last edited: Jan 6, 2017
  5. Reformed_Ocelot

    New Member

    Aug 5, 2018
    1
    0
    Would this work for a low amp 3.7v circuit?
    Is there a parts list for this? 3.5s is just right.
    How small of a package do you think you could make this awesomeness?
    I would like to piggy back an existing button on a controller to switch off/on the controllers power on a long press, this should work if I'm not mistakin.

    Any help is much appreciated
     
  6. crutschow

    Expert

    Mar 14, 2008
    23,096
    6,850
    Yes, the circuit will work down to 3V.
    The simulation below shows it working at 3.7V.
    upload_2018-8-5_0-36-21.png
    --- Bill of Materials ---
    Ref. Mfg. Part No. Description
    C1 -- -- capacitor, 22µF
    C2 -- -- capacitor, 22µF
    D1 OnSemi 1N4148 diode
    D2 AOT AOT-2015 diode
    D3 OnSemi 1N4148 diode
    Q1 NXP 2N2222 bipolar transistor
    R1 -- -- resistor, 237K, 1%, 0.1W
    R2 -- -- resistor, 1K
    R3 -- -- resistor, 100K
    R4 -- -- resistor, 4.7K
    R5 -- -- resistor, 10K
    R6 -- -- resistor, 100
    U1 (unknown) CD4013B (unknown 3rd party model)
    U2 (unknown) CD4013B (unknown 3rd party model)
    You can make it quite small depending upon whether you are up to building in on a PCB with surface-mount parts.
     
  7. sentinels

    New Member

    Jun 30, 2019
    12
    0
    Hello:

    May I ask some question?
    If I replace U2 by a RC time delayed circuit, will it work normally?
    What is the function of R3, C2 ?
    May I connect preset of U1 to GND?
    Replace C2 by a small cap?
    Will it work normally?

    best regards
     
  8. crutschow

    Expert

    Mar 14, 2008
    23,096
    6,850
    No, because U1 needs a fast clock risetime to work properly.
    I don't add parts if they are not needed. :rolleyes:
    Set the output to OFF upon power-up.
    Only if you don't care about the state of the output when it's powered up.
    It may not reset upon power-up if the power-up ramp time is slow.
     
  9. danadak

    Distinguished Member

    Mar 10, 2018
    3,488
    785
    Udhaya, the following is an alternative way of doing stuff using micros that may be of interest.

    Don't tackle this for your design, just consider new tools out there where you no longer have
    to write code in the "standard" way.

    Sanp4Arduino (and other block languages, mBlock, Scratch for Arduino, Ardublock) are
    drag and drop gui blocks (left hand window) onto a canvas in middle of screen. You
    configure them, then tell tool to upload to Arduino. Tool compiles project creating
    Arduino code and then programs the Arduino.

    Videos on web how to do this. Once you get comfortable with the tool you can program individual
    UP chips, like the ATTINY85 and its variants. You use a low cost Arduino board to function as the programmer.

    upload_2019-8-14_16-16-32.jpeg

    Your design would look like this -

    upload_2019-8-14_16-13-26.png

    There are other block languages, all with their own "special sauce", and much in common. Once you
    learn one the rest are easy to work with.

    One other side advantage is you can look at the C code tool generates for you, should you desire to
    delve deeply into micros.

    Fun stuff, here in US 6'th graders are using tools like this to program basic robots.

    The advantage over a discrete design is

    1) No power up glitching
    2) Minimal components
    3) Timing accuracy (ATTINY85 is 2%)

    upload_2019-8-15_19-24-48.png

    Regards, Dana.
     
    Last edited: Aug 15, 2019
    JohnInTX likes this.
  10. danadak

    Distinguished Member

    Mar 10, 2018
    3,488
    785
    An afterthought.

    Should you decide to delve into block programming an excellent platform is
    an Arduino Nano board. Cheap (ignore price shown on URL page), ~ $3,
    and can be used at a later time to program parts like the ATTINY85.

    Board has xtal on it so timing related jobs, like delays, pulse widths, tones etc.
    very accurate

    https://store.arduino.cc/usa/arduino-nano

    [​IMG]

    Regards, Dana.
     
    Last edited: Aug 17, 2019
    ci139 likes this.
  11. danadak

    Distinguished Member

    Mar 10, 2018
    3,488
    785
    Corrected pinout error, changed logical test for user holding button
    longer than 5 secs so that when button hits 5 sec, LED turned on,
    and then if user keeps holding button program waits until user releases
    button before it starts a new "cycle" waiting for a button press.

    upload_2019-8-17_10-15-40.png

    Regards, Dana.
     
    Last edited: Aug 17, 2019
  12. danadak

    Distinguished Member

    Mar 10, 2018
    3,488
    785
    Same program done in mBlock, very similar, small differences in block
    usage. mBlock makes it easier to see code generated.

    upload_2019-8-17_10-12-36.png


    Regards, Dana.
     
    Last edited: Aug 17, 2019
    JohnInTX likes this.
  13. ci139

    Active Member

    Jul 11, 2016
    619
    88
    ? (a "sequre" design :cool:) it 1-st determines whether the consuming circuit is ON or OFF ... then "selects" where to send a "TRIGGER Pulse"
    Startup - Test - x010.gif M3 D9 C9 may need revision/re-design
     
    Last edited: Aug 17, 2019
  14. danadak

    Distinguished Member

    Mar 10, 2018
    3,488
    785
    Here is a better way to debounce the button in mBlock.

    This example just flips an LED on Arduino board, button set up has to
    be pushed then released in order to flip LED. Button can be active high or
    low depending on what you pass in DeBounce call as KeyState parameter.

    upload_2019-8-29_10-47-0.png

    Here is flow chart to show basic method to debounce a button.

    upload_2019-8-29_10-54-26.png

    Regards, Dana.
     
  15. danadak

    Distinguished Member

    Mar 10, 2018
    3,488
    785
    Here is the kind of crap a mechanical button produces, why debounce code is
    important -

    upload_2019-8-29_15-20-47.png


    Regards, Dana.
     
  16. ci139

    Active Member

    Jul 11, 2016
    619
    88
  17. eetech00

    Senior Member

    Jun 8, 2013
    1,619
    333
    Hi

    The LTspice BOM generator doesn't take into account the actual number of components within an IC package.
    I'm sure you already know that, but for the TS's benefit, there is really only 1 CD4013B IC required.
    The CD4013B IC has two D Flip-Flops in one package.

    eT
     
  18. ci139

    Active Member

    Jul 11, 2016
    619
    88
  19. sentinels

    New Member

    Jun 30, 2019
    12
    0
    Dear Sir :

    The upload file is some waveform.
    Channel 1 yellow is PWR_BTN
    Channel 3 Red is Q1
    Channel 4 Green is Q2/ STB_CTRL
    Sometimes Q2/ can not change status.
    If I zoom in the waveform.
    I found some glitch on Q1, so STB_CTRL change unnormally.
    I do not know why there is glitch on Q1?
    Could you help to solve this problem?
    Thanks

    Best regards
     
  20. crutschow

    Expert

    Mar 14, 2008
    23,096
    6,850
    I'm having a problem reading those files.
    Just use the Upload a File button to upload them directly to your post without zipping them.
     
Loading...