Sleep mode magnetic switch wake (Electron)


I’m gonna buy some decoupling caps and try @TheHawk1337’s suggestion, and hopefully, it will somewhat stabilize it!

I found some other links on the arduino forum that I can try too (very similar issue):

if not, then I will put @ScruffR’s suggestion (to switch to a hall sensor) as the solution, unless you got more ideas?

Thank you for your help!


I’m sorry but as I am not from an electrician background I don’t really understand what capacitor I should buy.

If I choose aluminium capacitors I can get 1uF and 2.2uF capacity, but then the voltage is minimum 16V.

as you say it’s MINIMUM 6.3V capacitors, can I use the 16V? what is the maximum Voltage?

And when you write:

With R1 = 10k it’d add ~1.1mW. R1=220 it’d add ~50mW

What does that mean about uF and Voltage value?

Sorry if this is basic knowledge :sweat_smile:



Yes minimum 6.3V so higher is no issue. The only thing with higher voltage ratings is that the capacitor becomes bigger and more expensive :wink:

For simplicity I’d suggest a hall sensor as @ScruffR suggested.

1uF is just a suggestion but I honestly don’t know what capacitance would work.


most reed switches are closed when the magnet is near, open when removed.

In practice the typical use state is closed with the magnet near (like a closed door). You should verify with a meter.


I read 0 volts when magnet is near, and 3.3 volts when magnet is removed.


How do you measure this? Because this is opposite to what I expected (and thus it should be “RISING” instead of “FALLING” in the code).


That’s the confusing part!

I’ve had my electronics engineer colleague have a look at the simple setup, saying: “That’s an easy fix, just try this.” he then tried several things like i already did, and after an hour he gave up, saying that it defies all logic. :sweat_smile:

I showed him the setups that worked with me closing the magnet, and it wakes up (FALLING). He then told me to just set it to RISING edge instead so it works with removing the magnet instead of closing the magnet. Of course, like I’ve already tried, the device didn’t wake up at all (closing or removing magnet).

That’s when he left.

So yeah…

I measure with a multimeter, direct 3v3 to one and ground to other.

Is there really no one else having trouble with this or is it just me?
If someone could just show me how they got a magnet contact switch to work with their device, this could be closed.
I mean odds of me being the only person in the community trying to use a switch like this as a sleep wake, is very slim. And this is a very beginner like issue (should be atleast)

Btw I bought the capacitors and they are on the way.


Can you first establish the actual behaviour of your reed switch by means of a continuity check with you MM?
While commonly reed switches are NO and close when the magnet is near some switches are different. There are variants that are directional/polarised, some switch between two poles (open one close the other) …
Especially if you have an opaque one it’s not always easy to tell :wink:


Be sure you have the switch connected to ground on one leg, the other the input pin.
Trigger on a rising edge. Put a 4.7-40k resistor pull up from the input pin to 3.3v.

Verify when you remove the magnet the voltage jumps to 3.3v across the switch.

If it does not trigger on rising there could be a bug.

Be sure you are on the latest stable firmware. The latest beta was unstable for me.

Look up you’ve got mail on hackster for a similar setup with sleep and a reed switch trigger.


When i use your exact setup, and program it to wake on RISING, it still wakes on both closing and opening the switch :frowning:

I get the capacitors tomorrow and will test a couple of setups and write an update to this thread.

Not giving up just yet!


As said earlier, when setting the interrupt for RISING or FALLING the interrupt will not trigger on the opposite edge, but your switch is creating the exact kind of edge you are triggering for in both cases - when applying or removing the magnet - due to contact bounce.

Update: Now you changed the wording of your post the statement makes sense :wink:


I fixed the “typo” :wink:


So… i got my capacitors and my god it works.

I found an AC interference protection setup for a button and used it for my reed switch:

But it didn’t react to either removing or closing the magnet switch, so I experimented a bit on my own and found this setup to work EXACTLY as intended:

Using this simple code:

void setup() {
  pinMode(D1, INPUT);

void loop() {

It could probably use some slight changes in resistor strength, but it works as i want it.


Thank you for your help, i really appreciate it :wink:


I made some changes to my gotmail code. It seems to be more reliable now.

I wanted it to sleep for long periods if the network could not be found and thingspeak not updated.

If a thingspeak update fails, it waits until 60 seconds and sleeps for double the normal interval of 1 hour.

I implemented the watchdog with a 2 minute timer. FYI I have discovered the watchdog must reset each sleep/wake event.
I never call a checkin and it never seems to reboot.

However, if the particle hangs for some reason, it should automatically reboot after 2 minutes. after the reboot it should attempt a reconnect and update. If the update fails it should sleep after 1 minute for 1 hour.

This way if my home wifi dies, the photon shuts down and reattempts an update an hour later. As always it will wake on interrupt when the door opens if that happens first.


Do you need the LiPo charger @macsboost ?
I thought the solar panel charged the LiPo just as it is when connected to Vin?

I’ve read the thread

And they write that there is already a battery overcharge prevention on the particle device.


The mailbox is operating on a photon… there is no battery charge controller on the photon. These boards are quite cheap, 10/ for 10$ so not a big deal to add. The electron however has a lipo charge controller onboard.