How to use a reed contact switch as an On/Off switch for Arduino board

Hello,

Not sure if this is really the right place to ask.
I would like to use a reed contact switch as on On/Off switch for my entire Arduino board (as if it was a regular on/off button). Actually i'm using the Adafruit Powerboost 1000C module to power on my Arduino from a Lipo battery so this module is the one that should be switched on and off to provide the power.

The first time (a magnet will come close to the reed contact) the signal will become HIGH and should power on my board/ Powerboost module. A next time a magnet will trigger again the signal on high, the board should get no power anymore an shutdown.

Is there a way (with or without coding) to achieve this? I've came across this reed module which might be handy for this but not sure how to achieve the desired result:

https://www.otronic.nl/a-61363207/sensors/reed-switch-sensor-module-voor-arduino-esp32-esp8266/?gclid=CjwKCAiA9tyQBhAIEiwA6tdCrIOpfqwh8VaViMgqCcQt-11V_5KAcaDGfPeqFi7mz4-Gp9GU3joEbBoCbnIQAvD_BwE

Thanks for your support

Maurice

Hi @Mojies
Hard to do in code if your processor is powered down.
A hardware solution could be to use a J/K flip flop (See tutorial)
Reed contact switching on and off forms the ‘clock’ for the bistable (one bit memory).
I would expect a lot of bounce on the reed which needs to be de-bounced before feeding the clock. I guess your module circuit does that?
Good luck!

just curious, why don't you use a basic ON/OFF switch on the power line?

I assume you have a whole system at the back of this that needs powering and that you can't keep the Arduino just in deep sleep.

an alternative to the flip/flop and using a reed switch:

The reed switch will need power, and given you are only interested in ON or OFF the module you point at is really over engineered.

if you really want magnet driven operation, a simple reed switch could be enough:

You will need of course to have some voltage coming on one side and the magnet will close the switch (proper anti-bounce hardware needed ➜ R+C), which will then be used as a triggering signal (acts as an external button) for a power switch for example one of those Pololu Power Switches (which draws some current as well, but minimal). The main function of this is really a pushbutton-based latching power control, where one push turns on power and another push turns it off which seems to be what you are looking for

Hi @J-M-L ,
Thanks for your support and apologies for my late response.

I purchased a Pololu Power Switch and tried to connect it to a Grove Magnet Switch (with reed switch) to switch on/off a LED as prototype. (first magnet contact should switch the LED on, the second time magnet contact should switch the LED off)

https://www.seeedstudio.com/Grove-Magnetic-Switch.html

https://www.pololu.com/product/2808

Pololu Power Switch: VIN connected to 5V battery source, GND to battery GND. VOUT to LED+, GND to LED-.
Now, by using the tiny pushbutton (on the switch itself) once I can switch on the LED, Pushing it again switches off the LED like i would like to happen for testing.

Then i'm trying to connect the magnet switch to operate the Pololu powerswitch with magnet proximity
VCC to 5V battery source, GND to battery GND.
When i connect SIG from magnet switch to ON pin of Pololu i can switch the LED on with magnet and have it stayed on after i remove the magnet (just like i wanted). But then i would like switch of f the LED when i bring the magnet again close to the magnet switch. A high (pulsed) signal on the OFF pin would do the trick but don't know how to get this.

NC pin is not used.

I also tried to connect the magnet switch in between A and B of of the Pololu switch but without success. I think because the magnet switch creates a pulsed HIGH signal on the SIG pin and would need a momentary switch between A and B.

Do you / does anyone know how to get the correct configuration for this?

Thanks again!

Capture that on a pin and have the arduino issue the pulse to turn itself off?

Great suggestion!, i will try that!

Thanks

Or a DQ flipflop with Qbar wired to D will toggle on every clock pulse (but you'll need to debounce the clock signal perhaps, whichever flip flop design).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.