Imp pin 1 wakeup pulse on switch opening and on switch closing?

In a previous question I got good answers from @Hugo and @dheadrick on how to invert the behavior of a SPST switch used to wake up the Electric Imp.

As my switch is closed most of the time I wanted the Imp to wake on the switch opening and then, after doing some work, just wait for the switch to close again before going back into deep sleep.

There’s a significant difference between the 30uA draw I see in deep sleep and the 3mA I achieve when idling with wifi disabled waiting for the switch to close.

Thinking about things I see that ideally I’d deep sleep both when the switch is open and when it is closed, and wake only momentarily when the switch transitions from one state to the other, i.e. from open to closed or from closed to open.

So it seems to me I want to generate a pulse to wake the Imp on these transitions.

I’ve looked hard on the web and come across lots of one-shot pulse circuits. Most involve the 555 but it seems to draw so much current itself that it would be pointless using it in a circuit intended to save power. Also most of the circuits I’ve found generate a pulse on the incoming signal going from low to high but not also on going from high to low.

My background isn’t electronics and my own ideas fall into the kind of “if all you have is a hammer then every problem looks like a nail”, i.e. I think in terms of the small number of components I already understand, e.g. I’ve been thinking about fun circuits based around DPDT relays, caps and hex inverters (and I didn’t even know about them until recently) that would probably consume Megawatts of power :slight_smile:

I’ve come across various things that, to my untrained eye look like they might do what I want, e.g. dual monostable multivibrator ICs that can trigger on both positive and negative edges (could I wire the one switch to both multivibrators, with one configured to generate a pulse on a high edge and the other on a low edge?). But there are so many variants and the datasheets are so complex I get lost in all the details, e.g. looking at the SN74LS221N I can’t even work out it’s power consumption :frowning: And anyway it looks like it’s min voltage is too high for a 3.3V setup.

Thanks for reading and I hope you don’t feel my questions looking for cookbook like answers show a lack of effort in getting to grips with electronics.

Regards,

/George

Hi I found myself in the same position limited electronics skills and need to wake the imp on a switch going high or low. In my case to detect a door being opened and then closed.

I found this very low powered 555 <5uA

A as you say most examples are low to high but I found away round but can’t find the circuit will have a good to see if I can.

That said waking an imp from a single sensor/switch going high or low must be common use case?

If you are not averse to adding a microcontroller to your circuit, Microchip makes a 6pin SOT-23 or 8pin DIP microncontroller PIC10F200 that consumes 100 nA in standby mode, and 300uA running. It has a wakeup pin which you can connect to your switch so that it mostly sleeps. A little bit of code that says “if switch state changes - generate a pulse” is all you will need to create a solution that pulses on switch open and close.
I checked on Mouser and it’s dirt cheap @ $0.50 in singles. Building something with gates and timers will cost you more real estate on a PCB board and dollars in parts.

I’ve never used this device so I’m sure there are challenges getting it working, but it looks like a low cost solution to this problem. Here’s the datasheet for it:

If you get it working, you can sell it back to the rest of us who need this feature for pin1 wakeup!

The other way to do this is to just use a capacitor and a drain resistor.

SPNC switch with one side connected to 3.3v. Other side is connected to pin 2 directly (to read state, if needed), and also to a capacitor, say 10uF, and maybe a 100k resistor to ground. The other side of this capacitor is connected to pin 1. Pin 1, when asleep, has an internal pull-down.

When the switch opens, you get 3.3v on one side of the cap: this transition moves to the other side, generating a rising edge on pin 1 and waking the imp. When the switch is stable, the voltage on the pin1 side will slowly drain off due to the pin1 pulldown, returning the line to low so you can sleep again. You’ll need to configure pin 1 as a digital_in_pulldown in your code - the default pulldown when in sleep goes away when you wake up.

When the switch is released, the cap’s voltage will drain off slowly through the 100k to ground on the switch side, and this transition is slow enough that you’re unlikely to see a negative voltage on the imp side (you can use a diode here too).

@hugo, I can see how this will pulse when the switch closes. But, when the switch opens. how does it pulse? Imagine monitoring a door - when the door closes the switch closes and generates a pulse on pin 1, the imp wakes up, sends a message and goes back to sleep. When the door opens some time later, the switch opens and generates a pulse on pin 1, the imp wakes up, sends a message and goes back to sleep.
A pulse is needed when the switch opens, and another pulse is needed when the switch closes. I can’t see how that happens with your proposal - could you elaborate?

@deonsmt - the behavior you describe exactly matches my use case. My particular “door” tends to stay in one state or another for a long time, i.e. while biased towards closed it isn’t as if the open events are just momentary and not worth taking into account from a power saving perspective.

@deonsmt - I’ve been looking at using an ATtiny45 (0.1uA sleeping and 300uA when active, so same as your PIC10F200 but a little more expensive). Just existing experience with Arduino leads me to favor Atmel.

Something in side me feels uncomfortable at using an MCU, however small, to solve a problem that should require at most a few gates, resistors and caps :slight_smile:

But it’s hard to argue with the form factor, price and flexibility of these cute little 8 legged MCUs.

Will be sure to sell the solution back to the community if I get this working :slight_smile:

@ghawkins - I know the feeling. Like using a tank to crush a nut! But it’s smaller than a tank, and a lot cheaper!

A classic edge detector circuit using an Exclusive Or gate attached.

Input driven by PB switch and pull up/down resistor connected between Vcc & Gnd Capacitor value as required - suggest 100n ish

Perhaps use other gates in package for switch de-bounce if required

@MikeM - could you sketch what you mean with the additional pull up/down and cap? It would be a big help.

Perhaps something like the attached. You would need 1/4 of CD4070 quad ex or gate or use a surface mount single gate package. RC values are guestimates but will work ! Have also added simple switch de-bounce on input. Other gates in package could be used for more sophisticated switch de-bounce or inverting output etc.

@MikeM - thanks, that’s a nice solution!
I did a little digging into the specs of a single XOR gate SN74LVC1G86 and MC74VHC1G86DFT2G , and found that they can be had for about $0.38 in singles. With 2 resistors and capacitors, the BOM ends up at about $0.70. Similar parts from fairchild, On Semi etc. all roughly priced the same at distributors.
For current consumption, ignoring the current through the 10K resistor when the switch is closed, the XOR gates consume from 1uA Icc to 10uA depending on the manufacturer (MC74VHC1G86DFT2G from OnSemi 1uA, SN74LVC1G86 from TI 10uA). The switching current of the TI chip is 500uA but I don’t see a spec on the OnSemi datasheet.
I think I am still going to do the tiny micro solution. I can control the pulse width easily and maybe use the other outputs for other things.

Sorry for hi-jacking this thread @ghawkins :slight_smile: