DIY Arduino Power Shield: Push Button On/off, Auto Shutoff, and External Watchdog Timer

by JD_K in Circuits > Arduino

2581 Views, 19 Favorites, 0 Comments

DIY Arduino Power Shield: Push Button On/off, Auto Shutoff, and External Watchdog Timer

Title slide for Instble3.jpg

An Arduino shield is a circuit board with electrical components already permanently set up. This board is then plugged right into an Arduino board, making all the connections of the components fast and convenient, and error free. You can buy ready-made ones, but this one I made with discrete components soldered on a perf board. I designed it to add on to other Arduino projects, so it has many, many connection options, with the following features:

  • Pushbutton to power on
  • Programable pushbutton to shut off
  • Programable auto shutoff
  • External watchdog timer to reset the Arduino if it freezes
  • Optional ATtiny85 to control these functions, freeing the Arduino’s resources to handle other tasks


Reason for starting this shield: In a data logging project with a battery-operated Arduino, I was recording to a microSD card. When I went to retrieve the data, the file was corrupted and all of my data was lost. This actually happened multiple times. I eventually figured out that that when the battery died the microSD card reader must have been recording to the card and so the file was not closed, and thus not saved. So, I decided to make an Arduino shield that would allow the Arduino to monitor the battery voltage and stop trying to save data when the battery started getting too low. Since I was going to the trouble of making a shield, I decided to add other features.


Background resources: The ideas for this project are a compilation of different sources I found on the internet. Please look them up if you want more information. Indrek Luuk wrote an article on a website called circuitjounal.com regarding the auto shutoff circuit for the Arduino. Ralph Bacon also made a YouTube video on an auto shutoff circuit, but currently he always uses a dedicated chip (SI4599) which has the dual MOSFETs like the circuit described here. Ralph also discussed the external watchdog timer circuit on YouTube, but he based that on an article written by Wolfgang Borst which is published on the internet in ElektorMagazine.

 

In this Instructable I present the Fritzing image of the circuitry of my DIY power shield, some example code and video demonstrations. Since much of it is explained in the above-mentioned sources, I will not repeat the finer details of how the electronics work, but if you have questions for me, feel free to leave them in the comment section at the end. I include a couple of videos showing the pushbutton/auto shutoff and 555 timer setups on a breadboard to demonstrate them working separately from the shield.

Supplies

General Components for the shield

  • 6cm x 8cm perf board
  • Screw terminal
  • Two switches (SPDT)
  • AMS 1117 5Volt voltage regulator
  • 3-pin 90-degree male header pins (to solder to the pins of the AMS 1117)
  • Two 10uF tantalum capacitors (for the AMS 1117)
  • One micro-USB port (remove the data pins)
  • Female header pins (3-pin, 6-pin, two 8-pin, 10-pin)
  • Male header pins (ideally various colours, I used a total of 63, some pairs, triplets, etc.)
  • Two 10 kOhm resistors
  • Lots of jumper wires
  • Jumper connectors (about 10, to connect adjacent male header pins)


Components for the pushbutton ON/OFF circuit

  • Logic-level N-channel MOSFET (I used FQP30N0 6L)
  • Logic-level P-channel MOSFET (I used IRF9630)
  • Momentary pushbutton
  • two diodes (I used Schottky diodes, both regular rectifier diodes should work)
  • 10 kOhm resistor
  • 100 Ohm resistor
  • 47 kOhm resistor


Components for External Watchdog Timer

  • 555 timer IC
  • 8-pin IC socket
  • One 1 MOhm (for 555)
  • Two 200 kOhm (or 400 kOhm, for 555)
  • One 10 uF electrolytic capacitor
  • Two 100 nF ceramic capacitors
  • One 10 nF ceramic capacitor
  • Logic-level N-channel MOSFET (FQP30N0 6L)
  • Rectifier diode
  • 10 kOhm resistor
  • 27 kOhm resistor


Components for the Optional ATtiny85

  • ATtiny85
  • 8-pin IC socket
  • 10 kOhm (optional pull up for reset pin)

Tools: Soldering iron, needle nose pliers, X-acto knife and file if you want to trim the edge of the shield, multimeter, etc.

Making the Shield

Sheild front oblique.jpg
Shield4_ATtiny_555_externalWatchDog_autoshutOnOff_imageOnly.jpg
Sheild_JumperConnections_linesPNG.png
Sheild left side.jpg
Sheild right side2.jpg
Sheild top.jpg
UnoPins1.png
UnoPins2.png

If you want to make a shield like this, this section includes a fritzing diagram of the circuit, and pictures of the shield. I will include video demonstrations and files for the code used in the relevant sections later in this Instructable. Certainly, there could be improvements, or some parts, like the ATtiny85, could be left out. I also include a legend which notes the function of each jumper connection and hints about what other connections may need to be made. This shield has a myriad of options which are made available by using the jumper connectors on male header pins that connect components. By doing this, the shield is adaptable to use with whatever future project or another shield I choose to use it with. If a project or shield used a pin for a certain purpose, I have options to choose from to use a different pin just by changing the position of the jumper connectors. With all the options using the shield is confusing at first, but if you use the Fritzing image and the legend with all the jumpers marked (J1, J2, J3, etc.) you should be able to figure out what to connect and what to disconnect. 


Notes about how I made the shield…


Many people use stackable pins for their DIY shields, but I find they are too easily bent, and are too long to fit the shield tightly, so I don’t bother using them. For plugging into the Arduino pins I use male headers on the bottom. To accommodate the pin spacing between D7 and D8, I bend each of the pins from D8 to D13, all the way to the SDA and SCL, with needle nose pilers. And to be able to plug another shield on top of mine, I use female header pins, bending the pins from D8 to SCL just like I did with the male pins. The both lines of male pins are in the row to the left of the female pins, so I am able to stack other shields on top of this one. To help me discern which female header is which on the final product, I print out a label with each pin marked. I will include the file I made for identifying the pins on the female headers. Instructables does not allow a .docx file to be uploaded so I will upload a couple of pictures of the labels that I use on a sheet of address labels to print wit my printer and cut them to size with scissors. If you try this, you will have to play around with the size a little to get it right.


When making your own shield be aware of how much space you have between the components of an UNO and whatever is on the underside of your shield (maybe that’s why stackable pins are so frigging long). For example, the ATMEGA 328P chip on an UNO can take up a lot of space, and if you have a lot of wires or components on the underside of your shield, it may not fit.


Remove the data pins of the micro-USB port since they are not being used and you do not want to risk shorting them to the positive and negative voltage pins of the port. The pins are very small so use a precision screwdriver. I placed the red (for positive voltage) and black (for ground or negative voltage) in the holes of the perf board next to the pins then flooded the holes with solder so that the connection between the pins and the respective wires were made. Then test the connections to make sure there aren’t any shorts between the two wires, and the data lines! I did this by sacrificing a useable micro-USB cable and cutting it to expose all the little wires inside. I then plugged it into my newly soldered port and used the continuity function of the multimeter on all the wires inside the USB cable to ensure nothing, power lines or data lines, was shorted together.


The AMS 1117 is a surface mount component; however, I took a 3-pin piece of 90-degree male header pins, pushed the plastic to one end and soldered the three pins of the AMS 1117 to those three pins. So, with female header pins, I can insert or remove the AMS 1117. The datasheet for the AMS 1117 describes using tantalum capacitors, so there are two 10 uF tantalum capacitors soldered to the connections for the female headers. Caution, note the polarity of the capacitors!


I soldered the P-channel MOSFET upside down on purpose. I wasn’t sure if it would ever need a heat sink. So, there is a hole drilled through the perfboard in case I ever need to put a screw through the board to attach a heat sink to the P-channel MOSFET. So far, I haven’t needed one.


The male header pins for the jumper connectors come in a few arrangements (see the images above including the "Locations of Jumper Connections" and the Legend (a pdf file) below). These allow me to modify the connections depending on what I need the shield to do. So, for example, at J4 there are four male header pins. The centre pin is used to connect power to the rest of the shield. So, if you connect the jumper connector between the top and centre male header pins then the micro-USB port is connected to power the shield. I refer to this connection as “J4 top”. Likewise, if I want to connect directly to the battery instead, I would connect “J4 left”, which then connects the centre pin directly to the battery’s V+. With the pins arranged in this way, only one voltage source can connect to the shield at a time which is important. Another arrangement is something like J1, where there are only two male pins, placing a jumper connector here will enable that portion of the circuit. In this case, the voltage divider is now connected to the battery which will be used for monitoring the battery voltage. The last type of connection is where you have a choice of Arduino pin to perform a function. For example, J6 and J7 have the centre pins each connected to a single Arduino pin. You I could connect that to a pin on its left or its right. However, you would only connect one Arduino pin to the left connection and one to the right connection (You wouldn’t want to use both, for example, to monitor the battery voltage). 

Options for Powering the Shield

AMS1117_top.jpg
Sheild front2.jpg

Overview

The Arduino can be powered through this shield with the following options:

  • Screw terminals (e.g., connected to a battery) using the Arduino voltage regulator via the Vin pin
  • Screw terminals with an AMS 1117 voltage regulator
  • Micro-USB cable (no data lines, and no voltage monitoring)

Other notes:

  • Emergency off switch – cuts power to the Arduino and most of the shield regardless of other hardware setup or programming
  • Override switch – maintains continuous power to the Arduino regardless of other hardware setup or programming


Connecting a battery:

Connect the battery leads to the screw terminals, or the red (+V) and black (GND) male pins next to the screw terminals. Unlike all the other jumper connections on the shield these two must NOT be connected together because that would short circuit your battery! Select the battery to power the Arduino directly by placing a jumper connection at J4 between the center pin and the pin on the right (“J4 right”). Since this may be a 9V battery which is not a regulated 5V source, connect the two pins at the bottom of J5 (“J5 bottom”) to ensure that the battery voltage goes to the Arduino’s Vin pin (and not the 5-volt pin as that could damage the board).


Using the Voltage regulator on the shield

The voltage regulator in this shield uses the 5-volt AMS 1117. So, the input voltage on the screw terminals must be at least 7 volts, and if you are not planning on monitoring the battery voltage it can be as high as 12 volts. The AMS 1117 chip has a maximum output current of about 1A.


To use the voltage regulator of the shield, the connections would be:

  1. Select the voltage regulator at J4 (bottom), and enable the voltage regulator at J3
  2. Select either the 5V pin (top) or the Vin pin (bottom) of the Arduino at J5
  3. Remove any jumper at J9 if not using the 555 or ATtiny85


Using the micro-USB

Instead of connecting to the screw terminals, you can plug in a micro-USB cable. This would allow you to connect to a power bank, or to the wall outlet with a normal micro-USB cell phone charger. Note that when making this, I removed the data pins from the micro-USB port with a precision screw driver and used the continuity tester of a multimeter to make sure they were not shorted to the positive and negative voltage lines. So, you cannot use this micro-USB port to program or communicate with the Arduino.


To use the micro-USB port to power the shield and Arduino:

  1. Select the micro-USB port as a power source at J4 (top)
  2. Select either the 5V pin (top) or the Vin pin (bottom) of the Arduino at J5
  3. Remove any jumper at J9 if not using the 555 or ATtiny85
  • Note: no USB data pins are connected
  • Note: not set up for monitoring the voltage of the micro-USB connection


Emergency Off switch

This will power off the Arduino, MOSFETs, ATtiny85 and 555 timer regardless of the set up of the board. On the shield it is located near the voltage regulator. One drawback is that with this shut off, the voltage regulator and the voltage divider could still be connected, so it could slowly drain a battery connected to it.


Override switch

This will power the central pin at J5 from whatever voltage source at J4 is selected, regardless of the set-up of the rest of the board. This switch is located next to the emergency off switch. This will not work if the emergency off switch is engaged. This override switch can be useful when you don’t want the board to power down because you are troubleshooting other functions of your Arduino. As a reminder, if you are using this, and not using the 555 or ATiny85, then remove any jumper at J9 so that these two components will not draw any current. 

Operating the Shield - Push Button Options:

DIY Arduino Power Shield Demonstration of Pushbutton On/Off and Auto Shutoff
Pushbutton circuit.jpg
Breadboard Circuit of Pushbutton on/off and Auto Shutoff of DIY Arduino Power Shield
Pushbutton_Autoshutoff2.jpg
Pushbutton_Autoshutoff_top.jpg
Pushbutton_Autoshutoff_back.jpg

The pushbutton can be used with the following options:

  • Push button on with the Arduino sketch maintaining power (latching), the Arduino can be programmed to shut off power at some event or time
  • Push button on and off, using a digital or analog pin to monitor the button
  • Push button on and latching, then using the ATtiny85 to monitor the button to switch off power


In this section I include a video demo of the pushbutton on the shield and another video to show the circuit on a breadboard. There are pictures of the breadboard circuit and a picture of the isolated components. There is also the coding I used with the Arduino.


The way this works is that the gate pin of the P channel MOSETs is pulled high through a 47 kOhm resistor. When the button is pressed, it pulls this pin low, which will allow current to flow from the source pin to the drain pin. This drain pin will provide power the Arduino. However, if the button is released at this point, the gate pin is again pulled high and the current will stop. So, the N-channel MOSFET is used as a latch. Something must pull its gate pin high (opposite to the P-channel) to activate it. In so doing, the drain of the N-channel mosfet will keep the current flowing in the P-channel mosfet. The power shield has several options at J8 to latch (an Arduino pin, the 555 timer, or the ATtiny85).

 

Connections to latch with the Arduino to turn on (no external watchdog timer)

Select the Arduino at J8 (right), then one of the Arduino’s digital pins, D4 or D5 or D6, at J15. The reason for the multiple pins is to allow for flexibility with whatever other components you have connected to the Arduino.

In the programming of the Arduino, bring this digital pin at J15 HIGH early in the setup and this will act as the latch to keep both MOSFETs powered and thus the Arduino as well. If in the programming this pin at J15 is brought LOW, then the power to J5, and the Arduino itself, will power off and not restart until the button is pressed again.


Adding the Push Button Off option

With this option, after the button is pressed to turn on the Arduino, a subsequent button push can power the J5 pin (and thus the Arduino) off. To accomplish this, one of the Arduino pins must monitor the button to detect the push. The shield is set to do this with an analog pin (A2 or A3), a digital pin (D8 or D9). In the programming: the button is monitored (digitalRead), and if it is brought LOW, then the output pin to J8 (see “Push Button ON” section) should be brought LOW.

 

Here are the connection options to select which pin will monitor the push button at J16:

  • To use an Arduino analog pin: select J16 top, and select ether pin A2 or pin A3 at J7; Note here the analog pin is being used as a digital I/O pin
  • To use an Arduino digital pin instead: select J16 bottom, and either pin D8 or pin D9 at J12

Note: There is an option to use the ATtiny85 (right at J16). The way the shield is set up, this would be pin1 on the ATtiny85, which would involve programing this reset pin as a digital I/O pin. If you do not want pin1, then you must use a jumper wire to connect the white pin next to pin1 to a different ATtiny85 pin.

Note: Depending on your sketch, you may have to hold the button down to power off. If you are making a shield like this, you may want to connect the button to an interrupt pin (D2 or D3) so that you do not need to keep polling to see if the button is pressed.

Operating the Shield - Battery Monitoring:

DIY Arduino Power Shield Demonstration of Low Battery Voltage Detection

Here is a video showing the battery monitoring, and the code I used on the Arduino.


There are a pair of 10 kOhm resistors connected to the screw terminals which are used to divide the voltage by two. Using these two resistors 1) reduce the amount of current consumption for battery monitoring, and 2) allows a maximum of 10volts to be monitored by the Arduino. Monitoring the battery can be used to shut off power to the Arduino when the batteries are low. As I said before, this can be useful if you are data logging with an SD card because if the battery dies when you have the data file open you will lose the *whole* data file (file corrupted).


The connections to enable battery monitoring:

  • Enable J1;
  • If powering the Arduino’s Vin pin directly from the battery, select the battery voltage (left) at J4; but ensure the voltage regulator is NOT connected at J3. See next section for more information on the AMS 1117 voltage regulator
  • If powering from the voltage regulator, but still want to monitor the raw battery voltage: select the voltage regulator at J4 (bottom), and enable the voltage regulator at J3. This will allow the battery to power the 555 timer and Arduino from the AMS1117
  • Use J2 left and J6 to monitor the battery voltage by the Arduino (left) at either pin A2 or A3, or
  • Use J2 right to monitor the battery voltage by the ATtiny85 and connect D2 pin of the ATtiny85
  • Finally select either the 5V pin (top) or the Vin pin (bottom) of the Arduino at J5


Notes:

  • Cannot measure the voltage of the voltage regulator or the USB voltage input
  • The voltage should not exceed 10 volts (so a 9V battery is fine)


The two 10 KOhm resistors connected to J1 will half the voltage measured. So, in the programming you will have measure the analog value, convert that to voltage but double the measured voltage. For example, if measuring the battery with pin A2 of the Arduino, the code would be something like this:

float voltage = (analogRead(A2) *5.00)/1024; // the voltage measured at the voltage divider

voltage = voltage * 2; // double this value to get the actual voltage of the battery

If you plan to cut power to the Arduino when the battery is low, you would not be using the external 555 watchdog timer (see the section on the 555 watchdog timer below)


Operating the Shield - External Watchdog Timer

DIY Arduino Power Shield Demonstration of an External Watchdog Timer using a 555 Timer
Watchdog Timer circuit.jpg
Breadboard Circuit of External Watchdog Timer for DIY Arduino Power Shield using a 555 timer
555WDT.jpg
555WDT_top.jpg
555WDT_side.jpg
555WDT_back.jpg

Using a 555 timer integrated circuit and external watchdog timer is created, that will momentarily shut off power to the Arduino to reset it. This shut down is prevented by sending a pulse to the 555 timer at regular intervals of about 10 seconds. (To see how I figured out the components for the timing of the 555, see this Instructable (link).) So, if the Arduino is signalling the 555 timer, and freezes this external watchdog timer will time out and reset the Arduino back to normal function. This is useful if you plan to have your Arduino run for an extended period of time unattended. If it were to freeze you would not know that it stopped working, but with the timer it would just reset itself and keep working.


In this section I have included a video demonstrating the timers External Watchdog Timer on the shield and another video showing the circuit on a breadboard. There are pictures of the circuit, and the code used on the Arduino.


Options for the External Watchdog Timer:

  • Watchdog timer that is pulsed by the Arduino
  • Watchdog timer that is pulsed by an ATtiny85

** With the external watchdog timer, the pushbutton would not be enabled. To switch on/off the shield use the Emergency Off switch.


This function is for long-term, unsupervised Arduino projects and prevent them from locking up (freeze) which would stop them from working even though they are still powered. This uses the 555 timer in an astable multivibrator circuit, which is set up to give an output signal of 10+ seconds High, and 5 seconds LOW. When this low output is connected to the two MOSFETs, the power (to J5) would be shut off and therefore shut off the Arduino. If a signal is pulsed to 555 timer every 10 seconds or less, the output of the 555 would remain HIGH and never go LOW, and the Arduino would continue working uninterrupted.

The purpose of this is to have the Arduino pulse a signal to the 555 timer, and if the Arduino ever freezes, the power to the Arduino would shut off for the 5 seconds because of the two MOSFETs and then restart when the 555 timer goes HIGH. This is basically a hard restart of the Arduino, and is called a “Watchdog Timer” (WDT). When the Arduino restarts, it can then begin the pulses to the 555 and the power would remain on. Ideally the Arduino would never freeze, and the output of the 555 would never go LOW


The pulsed signal to the WDT occurs at J13 and goes through a series of resistors, capacitors a diode and a separate N-channel MOSFET. These components will stop the pulsed signal if J13 is no longer pulsed, meaning if the pulse at J13 is frozen in either a HIGH or LOW state, these components will stop pulsing the trigger pin and the 555 watchdog timer would them timeout and reset the Arduino.  


To connect the 555 external watchdog timer:

  • Select the power source to the 555: bypass the dual MOSFETs (right at J9) and enable the 555 at J10, in this case the ATtiny85 is powered by the battery or micro-USB and would not shut off even if the Arduino does
  • Select J13 right, to connect an Arduino digital pin for the pulse, select either D4, D5 or D6 at J14

Although not normally used, you could select J13 left, to connect an ATtiny85, and enable pin3 of the ATtiny85 to pulse the 555 timer

Operating the Shield - Optional ATtiny85

As described above the ATtiny85 can be used to monitor the battery, monitor the push button off, pulsed the 555 WDT, or signal the dual MOSFETs to turn on/off power to the Arduino. This could be useful if you do not want to take up any of the Arduino’s recourses (memory or runtime) to perform these functions. You could program the ATtiny85 to dedicate it to the functioning of the shield, and programming for the Arduino does not need to be modified.


Because the Arduino UNO is not a low power device, the ATtiny85 could be used in low power (sleep mode, 3.3V, slower internal clock speed) and then turn on the Arduino in response to a sensor. This would minimize power until the Arduino and its connections were needed by using the ATtiny85 to turn on (latch) the MOSFETs.


Connections to use an ATtiny85 to latch the dual MOSFETs ON

Select power to the ATtiny85 either the dual MOSFETs as part of the auto ON/OFF mechanism (left at J9), or directly from the J4 voltage source (right at J9)

Enable the ATtiny85 at J11

Select top at J8, and pin6 of the ATtiny85

Program pin6 to go HIGH to latch on, and LOW to shut off power to the dual MOSFETs 

Conclusion

This is the end of this Instructable. I hope you found it educational, and perhaps found some ideas for making a project on your own. There are lot of options to explore to help add functionality to your project!