Description
May products requires a functionality to turn ON/OFF the power of the device using single switch. Soft Latch Circuit can be used for the same. A Soft Latch circuit is different from the normal latching circuit, in soft latch the on and off states can be changed using external means (push button) but in normal latching circuit, the circuit can only be latched to only one state, and to change the state the power supply need to be removed.
There are many soft latch circuits available.
Most of the above circuit uses the Power Mosfet / Transistor to ON/OFF the power but in many application we use the microcontroller and voltage regulator (LDO). So this circuit is optimized and use the LDO instead of the Mosfet and transistor to implement the latching logic. This will be helpful to minimize the hardware cost of the product and keep the circuit size small.
Working
The circuit operates as:
- Single Button Press - Turn ON the device
- Hold Button for 3 sec - Turn OFF the device

The circuit uses a LDO which has a active high enable pin. The LDO can be used as per the design requirement. Here I used SPX3819 which is a 5V to 3.3V LDO. An Atmega8 controller is used as a microcontroller. Two Atmega8 GPIO are used for input and output. Here the Vin voltage is 5V but we can use any voltage as per the need, only has to change the R1 and R2 values in the circuit (explained below).
Working flow
Power ON flow
- When the system gets powered, it stays in OFF condition because LDO Enable pin is in pull down condition (Internally pull down).
- Once the S1 switch is pressed, R1 and R2 forms a voltage divider and ~3.4V forms at the R1,R2 junction.
- The 3.4V passes from D1 and it pull the Enable pin of LDO high. So the LDO powers the controller.
- Once the controller powered ON, a code will set one GPIO as output which is connected to the LDO enable pin and keep the GPIO high.
- So after releasing the switch the LDO stays on because the GPIO provides the power to the LDO enable pin.
Power OFF flow
- When the button is presses for 3 sec, the code in controller sense the button presses from the another Input GPIO.
- After 3 sec passed, the controller set the Output GPIO low so the LDO gets turned OFF and power OFF the device.
- The 3 second logic is implemented to prevent the accidental power off the device due to short switch press. This time can be adjust using the code.
R1 and R2 voltage divider
R1 and R2 is used to lower the VIN voltage to the controller’s GPIO sensing voltage range. let’s assume that if the input voltage is 9V then directly passing 9V to controller can damage it. So R1 and R2 forms a voltage divider network. The values can be calculated using the simple formula. Here the Input voltage is 5V, So we wanted the GPIO sensing voltage in safe range. i.e. ~3.3V.
Vout = (Vin x R2 )/(R1+R2)
3v3 = (5V x 10k)/(4.7K + 10K)
- D1 is used to prevent the voltage going to Input GPIO of the controller when the device is in ON state (To prevent the ON/OFF loop). Schottky diode is recommended so that the voltage drop will be less.
Controller Code
The code is written in Arduino IDE, You can implement this logic with any controller. Below is the code:
void setup()
{
pinMode(3, OUTPUT); // set the GPIO 3 as output. PD3 (Pin1) on Atmega8.
pinMode(4, INPUT); // set the GPIO 4 as Input PD4(Pin2) on Atmega8.
digitalWrite(3, HIGH); //set the GPIO 3 high to enable the LDO when the controller gets power ON
while(digitalRead(4) == HIGH); //wait till the button gets released
//write this logic in the beginning of the setup
}
void loop()
{
turn_off(); // function to check if button is pressed
}
void turn_off()
{
if(digitalRead(4) == HIGH) //check if button pressed
{
delay(3000); //3 second delay after button pressed
while(digitalRead(4) == HIGH) // check if button still pressed and wait till the button is released
{
delay(10);
digitalWrite(3, LOW); //set the GPIO 3 low to turn off the LDO.
}
}
}
We can also use the timer interrupt if we dont want to use the delay function. delay function can halt the controller for 3second so it can not perform any other operations.
You can see the circuit demo which is used in one product