My thought was to use a magnetic reed switch to turn on the arduino. But how do I keep it running if the magnet is moved? The idea is that the application will determine when it is ok to shut off the power to the arduino.

I don't want any power usage when the system is dormant since it could be weeks between magnetic triggers.



You can connect a power MOSFET in parallel to the reed switch, that is controlled by the Arduino:


simulate this circuit – Schematic created using CircuitLab

The Arduino powers up, when the reed switch is activated. Then you can activate (drive HIGH) the pin connected to the MOSFET, so that the Arduino is still provided with the needed power through the MOSFET, if the reed switch turns off. If the correct time comes to turn the Arduino off, you can release the digital pin (drive LOW or high impedance/input), so that it get's pulled to low. That will deactivate the MOSFET, which cuts the power off the Arduino.

  • chrisl - I think this is exactly what I was looking for. However, I have one question: Since I am using 4 AA Batteries as a power source, should I connect the "Arduino 5V" connection in your diagram to the Vin pin instead? Will there be any other issues since I am using a higher voltage? - Doug
    – Doug Bower
    Sep 21 '19 at 0:37
  • No, the higher voltage should not be a problem (most MOSFETs have a rather high voltage limit). Only be sure, that the used MOSFET is rated for a current higher than what your total circuit needs. And it has to drive into saturation for 5V gate voltage
    – chrisl
    Sep 21 '19 at 7:37

Put your Arduino into deep sleep and attach an interrupt to a pin that is monitoring your reed switch. Once triggered it can run your code before deep sleeping again


The LowPower library will help you to minimize the amount of power used by putting the Arduino to sleep. The Arduino will awaken once the magnetic reed switch triggers it, then you can execute some code before it goes back to sleep again.

There is an example sketch that may work for you:

// **** INCLUDES *****
#include "LowPower.h"

// Use pin 2 as wake up pin
const int wakeUpPin = 2;

void wakeUp()
    // Just a handler for the pin interrupt.

void setup()
    // Configure wake up pin as input.
    // This will consumes few uA of current.
    pinMode(wakeUpPin, INPUT);   

void loop() 
    // Allow wake up pin to trigger interrupt on low.
    attachInterrupt(0, wakeUp, LOW);

    // Enter power down state with ADC and BOD module disabled.
    // Wake up when wake up pin is low.
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); 

    // Disable external pin interrupt on wake up pin.

    // Do something here
    // Example: Read sensor, data logging, data transmission.
  • Thanks for this solution. It's not exactly what I was looking for because of the power consumption (although it is very low!), but I plan on using this for other projects.
    – Doug Bower
    Sep 21 '19 at 1:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.