Author Topic: Power latching circuit for the Digistump Oak  (Read 91 times)


  • Jr. Member
  • **
  • Posts: 64
Power latching circuit for the Digistump Oak
« on: August 20, 2017, 04:42:45 pm »
This is not a full project in itself, but it could be used to power others. Plus, it was enough of a project getting it worked out that I'm posting it here -

Latching power circuits allow your Oak to turn on with a button press, then power down with a second button press or button release - but only *after* it has finished running its code, including any shut-down procedures. It requires a power supply of at least 5V so if you've been cheating and running your Oak off 3.3 or 3.7V, don't expect it to do so reliably.

Advantage of using a soft latching circuit versus the Oak/ESP8266’s sleep/wake functionality: power savings. The Oak draws 1 mA in sleep and 50-70 μA in deep sleep, if you've cut the trace for the on-board power LED. In contrast, when powered down this circuit sips about 1 μA, and you haven't mutilated your Oak.

This circuit can be used for either a push-on/push-off or latching type switch, or a momentary button:

Circuit schematic:

Here I’m using pin 8 to latch the circuit on, or keep it active until activity is detected on pin 9 - i.e. it goes low when a push-on/push-off switch is released, or high when a momentary contact switch is depressed a second time. The Oak then finishes running its code, then writes low to pin 8 to turn itself off. A more detailed explanation of this circuit at

Code showing how this works for a latching, push-on, push-off switch:

Code: [Select]
/* Power-latching circuit control code

Basic code for a power latching circuit. Pin 8 "latches" the power on, i.e. keeps the system powered
even after the switch has been released. In this version, pin 9 senses when the switch has been
released and executes the power-down code, which here is a simple 2-second delay before the
microprocessor powers itself off. */

const char *version = "power latch circuit";
uint16_t delayInterval = 500;                               //timing delay between code loops

#define PWR_LATCH P8
#define PWR_CHK P9

void setup() {

  pinMode(PWR_LATCH, OUTPUT);                               //initialize pin for output
  digitalWrite(PWR_LATCH, HIGH);                            //write HIGH to latch circuit "on"
  pinMode(PWR_CHK, INPUT);                                  //initialize pin for sensing power switch state


void loop() {
  if (digitalRead(PWR_CHK) == 1) delay(delayInterval);      //high reading - switch is closed or "on"
  else {                                                    //low: execute power-down code
    pinMode(PWR_LATCH, LOW);

Functioning breadboard version: