Introduction: Power Off From an Arduino Sketch Using the Pololu Power Switch

If you need an Arduino to shut off from within your Sketch, this is the solution.

We will explore wiring the Pololu Pushbutton Power Switch, programming the Arduino to shut off the power, and making the unit "power on" only.

The Pololu Pushbutton Power Switch comes in two versions - the SV version geared towards 4.5V-20V range, and the LV which specifies 2.5V-7.0V range. I will use a 9V battery for this demo, and thus the SV version of the power switch.

Webpage for the Pololu Pushbutton Power Switch

Parts List:

1 - Arduino (I am using an UNO R3 for this Demo)
2 - Solderless Breadboard
3 - Pololu Pushbutton Power Switch SV
4 - 9V battery and holder with power leads
5 - 2.1mm male power jack to plug directly into the Arduino

Step 1: Getting Familiar With the Pololu Power Switch

The power switch has 2 connectors each for GND, VIN and VOUT, allowing multiple attachment points for your projects. A digital connection labeled OFF allows a 5V signal to turn the unit off. The kit comes with 0.1" headers, making insertion into a Solderless Breadboard effortless, or into a 18-pin DIP for your project.

It also sports 2 connectors for a momentary contact switch, allowing you to use the provided switch directly on the board, or solder your own leads for a switch (or switches) separate from the unit.

Step 2: Setting Up the Pololu Power Switch

Attach the 9V battery leads Red to VIN, Black to GND on the Pololu Power Switch

I used a 2.1mm male power jack to plug directly into the Arduino, which regulates the voltage to something the Arduino can handle easily. GND on the Pololu Power Switch goes to the outer connector on the power jack, and VOUT (Red) goes to the inner connector. (See photo)

Pressing the momentary contact switch should power up the Arduino. A second press should turn it off. This is the same behaviour as a standard On/Off switch.

You can choose to either solder the included momentary contact switch to the PCB, or wire it separately to the Breadboard. Wiring it separately means you can use a different momentary contact switch, and/or mount it to your project cabinet. In the early shots of this project, I mounted the momentary contact switch to the PCB for simplicity of the photos, but in the later shots the momentary contact switch is mounted on the Solderless breadboard.

Step 3: Connecting the Pololu Pushbutton Power Switch to the Arduino, Upload Sketch

Connect Digital pin 7 on the Arduino to the OFF pin of the Pololu Pushbutton Power Switch. Upload the sketch below.

The Pololu Power Switch will turn off the power anytime it gets a HIGH signal on the OFF pin. This simplistic Sketch does nothing more the wait 5 seconds before turning off the power. The same concept applies in any Sketch you are working on - when the conditions you have decided on are met...Set the pin connected to the Pololu Power Switch's OFF connector HIGH, and the power gets shut off.

You can connect the Pololu Power Switch to any of the Arduino Output pins, but you will need to modify the Sketch to use the same pin.

The photo shows the momentary contact switch mounted on the breadboard, and the OFF line coming from the Arduino

void setup()
{
  //Prepare Digital Pin 7 on the Arduino for output
  pinMode(7, OUTPUT);
  //Set digital pin 7 LOW. HIGH turns off the Pololu Pushbutton Power Switch
  digitalWrite(7,LOW);
}

void loop()
{
  //Wait 5 seconds
  delay(5000);
  //Setting Digital pin 7 HIGH turns off the Pololu Pushbutton Power Switch 
 digitalWrite(7,HIGH);
}

Step 4: Pololu Pushbutton Power Switch As a "Power On" Only Switch

In the application I was researching for the Pololu Pushbutton Power Switch, it was highly desirable to have the momentary contact switch only turn the power ON, and never OFF - the Arduino needed to "decide" in the Sketch when the correct time to power down was.

Fortunately there is a simple way to make this work.

Instead of wiring the momentary contact switch into the 2 spots marked on the PCB, instead wire one side of your momentary contact switch to the connector CLOSEST TO THE END of the board, and the other side to GND. This will allow the momentary contact switch to turn the power on, but not off again. To power the unit down, either remove the power, or have the Arduino shut it off using the OFF connector.

Comments

author
Kev_MacD (author)2013-04-19

I am fairly sure you could just wire an ordinary switch to both the Pololu Power Switch as a "Power On" only switch as described and also to the Arduino at the same time and it would work fine, however if you wanted to be perfectly correct find a DPST momentary pushbutton. Your Arduino code would have to watch for a push to the button, run your operations and shut down the Pololu Power Switch

author
opnordahl (author)2013-04-18

I need to have a controlled powering down of my project. What I would like is to be able to sence the pushbutton pressed by arduino, then do some operations and then turn off the arduino. What I want is to use the pushbutton to switch on the system and to use the same pushbutton to send a signal to arduino to turn it off. My idea is to wire the pushbutton to both the Pololu Power Switch and to the arduino at the same time and then use the arduino to sence when the pushbutton is pushed. Is this possible?

About This Instructable

18,048views

10favorites

License:

More by Kev_MacD:Steampunk ESP8266 Internet connected Clock using the Arduino IDEReplace the touchscreen on a Garmin Oregon for $20Adding Free OpenStreetMaps to your Garmin Oregon 450 GPS
Add instructable to: