Converting a switch into a click/double-click pulse emitter

Discussion in 'Digital Circuit Design' started by Ted Benson, Sep 11, 2017.

  1. Ted Benson

    Thread Starter New Member

    Sep 11, 2017
    3
    0
    Hi all,

    I'm trying to convert a magnetic switch (like the things you nail to a window) into something that emits either clicks/double-clicks or clicks/long-clicks on close/open. Here's a diagram of the input/output signals I'm looking for: there are a few variations that would work (below).

    The back story is that I'm trying to figure out how to combine a magnetic window sensor with one of those Amazon IoT buttons so that I can register one event when the window opens and a separate event when the window closes.

    Thanks for any help!!

    [​IMG]
     
  2. crutschow

    Expert

    Mar 14, 2008
    22,530
    6,604
    The magnetic sensor is typically closed when the window is closed and open when the window is open.
    So why do you need the pulsee?
     
  3. dl324

    AAC Fanatic!

    Mar 30, 2015
    8,558
    2,065
    Welcome to AAC!

    You could use a dual one shot (e.g. CD4538), one triggered on the rising edge and one triggered on the falling edge.
    upload_2017-9-11_19-27-31.png
     
    Ted Benson likes this.
  4. Ted Benson

    Thread Starter New Member

    Sep 11, 2017
    3
    0
    Hi @crutschow,

    My plan is to solder it in place of the button on one of Amazon's IoT Buttons. These buttons let you send CLICK, DOUBLE_CLICK, and LONG_CLICK events to an API over a WiFi connection. So if I can map the window opening to CLICK event and map the window closing to the DOUBLE_CLICK event, then I can basically use the device as a way to send window open/close notifications to a home security API I'm building.
     
  5. Ted Benson

    Thread Starter New Member

    Sep 11, 2017
    3
    0
    Awesome, thanks @dl324 -- I appreciate the pointer! I'll have to do a bit of reading to grok this fully.. but that's the fun part :)
     
  6. crutschow

    Expert

    Mar 14, 2008
    22,530
    6,604
    Note that you will likely have to add a debounce circuit to the magnetic switch output to avoid false triggering of the one-shots.
     
  7. AnalogKid

    AAC Fanatic!

    Aug 1, 2013
    7,936
    2,241
    Should be a pretty simple circuit, maybe one hex inverter and some Rs and Cs.
    What power is available for the pulse circuit?
    What are the periods of the long and short output pulses?

    ak
     
  8. philba

    Active Member

    Aug 17, 2017
    959
    303
    I'm sure it's doable with some amount of logic but you might also look at a low end micro. Arduino Nano, Trinket or similar. The advantage of that is you can experiment with delays without changing the hardware. I suspect you will spend some time figuring out what the iot button needs to see.
     
  9. crutschow

    Expert

    Mar 14, 2008
    22,530
    6,604
    Below is the LTspice simulation of a circuit using a single 555 timer and a CD4077 XNOR gate pulse-doubler circuit (U3) to trigger the 555 on both the leading and trailing edge of the window switch operation.
    This gives your "Desired Output".
    The top XNOR (U2) generates the signal to change the time-constant and give a different output pulse-width for the leading and trailing edge pulses.
    The short pulse is determined by the R2C1 time-constant and the long pulse is determined by the (R2+R3)C1 time-constant.
    The circuit is also insensitive to any input switch bounce.

    upload_2017-9-12_0-33-36.png
     
    Last edited: Sep 12, 2017
    ebeowulf17 likes this.
  10. AnalogKid

    AAC Fanatic!

    Aug 1, 2013
    7,936
    2,241
    First pass at the "Desired Output". R1-C1 set the narrow output pulse on the input leading edge. R2-C2 set the wide output pulse on the input trailing edge.

    EDIT: See post #16 for an updated schematic that includes switch debouncing.

    ak
    DualPulser-5-c.gif
     
    Last edited: Sep 12, 2017
  11. crutschow

    Expert

    Mar 14, 2008
    22,530
    6,604
    I like that. It's a nice simple circuit.
    The only possible problem I see is that any input switch bounce will appear on the output (which may or may not be a problem to the Amazon IoT input).
    You may want to use the spare gate in a debounce circuit.
     
  12. AnalogKid

    AAC Fanatic!

    Aug 1, 2013
    7,936
    2,241
    Agree about debouncing. Scrambling for time, I left off the input and output connections.

    Magnetic reed switches don't bounce very much. Since the input is a dry contact and there has to be a pull down resistor anyway, a 1.0 uF and 22 K in parallel from the input to GND should do it.

    ak
     
  13. AnalogKid

    AAC Fanatic!

    Aug 1, 2013
    7,936
    2,241
    From a nice, simple guy.
     
  14. crutschow

    Expert

    Mar 14, 2008
    22,530
    6,604
    Might the capacitive surge current not weld the contacts?
    Since you have a spare gate, just connect that to the switch and use an RC delay at its output to the next Schmidt input.
    Something like this:
    upload_2017-9-12_17-53-36.png

    But of course. :D
     
  15. AnalogKid

    AAC Fanatic!

    Aug 1, 2013
    7,936
    2,241
    I had that thought about 5 minutes after I posted, but by then I was gone from the keyboard.
    I've never encountered a problem with sealed reed switch contacts welding. Bit if contact welding is a concern, you can increase the resistance and decrease the capacitance, both by 10x. Still, since there is that extra gate, the series R-C is the better solution. If you do that, swap R1 and R2 to maintain the logic polarity.

    ak
     
  16. AnalogKid

    AAC Fanatic!

    Aug 1, 2013
    7,936
    2,241
    Schematic update with debouncing of both the make and break edges.

    ak
    DualPulser-5-c.gif
     
    dl324 likes this.
  17. dl324

    AAC Fanatic!

    Mar 30, 2015
    8,558
    2,065
    This one gets my vote.
     
  18. Nu2Java

    New Member

    Sep 13, 2017
    6
    0
    Hi, I am new to this site. A lot of very exciting things to learn here. Can you tell me what this circuit will do when triggered by the magnet switch?
     
  19. AnalogKid

    AAC Fanatic!

    Aug 1, 2013
    7,936
    2,241
    See post #1 and post #10.

    ak
     
Loading...