i would like to ask you for help with design of an circuit.

I have and atmega328p, with detection for voltage on its Vin (Vcc). I have made and voltage divider and its output i connected to Analog Pin. And i would like to, if an voltage decrease under an certain level (4.5V), to shutdown itself (atmega328p).

As i said the voltage detection is no problem (there is an voltage divider), programing it is as well no problem, but i though that i program it like this:

Detect voltage on analog pin A0, if the voltage is less than certain level (4.5V), write to memory and send to digital pin 3 an "LOW" (0) logical state.

This will turn the mosfet off and the atmega will loose its ground (GND) and its shuts down, but i have there an pull-up resistor which when the atmega shutsdown takes its lead an set Gate at MOSFET to high (transistor will turn on) and atmega turns on, then it shuts down and this will do the infinite cycling until there's no power to turn on atmega.

I want to use an Supercapacitor (2.2F 5.5V) to power it when the main input is lost and to give an atmega a time to write to memory and steadily turns off.

I am adding an schematics to better look at the problem.

enter image description here

I know that there is no crystal and capacitors and the other things to make it reliable and fully functional, but this is not a subject of this question.Its an first sketch, which is not completed.

I know some ICs that can detect Voltage and turn its output to some logical state (1 or 0), like an MAX809 (803 or 810) and so on and of course this is my backup plan, but i want to ask you, if you have any great idea to make this without any special ICs and more easily? I also thought about some OPamp or thyristor maybe, i don't know......

Can you help me with an idea or better with an schematics how to do it ? Thanks.

  • You should be using a p channel MOSFET and switching the power not the ground. When I get home I'll draw you a schematic
    – Majenko
    Nov 10, 2018 at 20:54
  • @Majenko Thank you, i appreciate that, but i have already thought about that and i think it will be the same situation but with all logic states reversed. If i think right then at the p channel mosfet, when there is high state on base the fet is OFF and vice versa. So if i during the running of atmega send LOW to base, the transistor is ON a everything is good, but when i want to shutdown atmega, atmega will send HIGH to base, transistor is OFF and the pull up resistor will stick it HIGH (until cap will discharge), but when the power is recovered resistor keeps it HIGH and atmega wont start.
    – Vasekdvor
    Nov 10, 2018 at 21:30
  • if i use the pull-down instead of pull up, then when there is a power transistor is pulled down by resistor and its ON (good). When i want to turn transistor OFF, atmega will send HIGH to base of transistor and transistor will turn OFF (good), but when atmega dies, there will be no more HIGH at transistor base and the pull down resistor will turn transistor ON, and we have the same cycle as with the current schematics. Sorry i use BASE, i know that MOSFET has a GATE, not BASE....
    – Vasekdvor
    Nov 10, 2018 at 21:37
  • 1
    The trick is to have the arduino keep the system on, not tell it to turn off.
    – Majenko
    Nov 10, 2018 at 22:06
  • 1
    @frarugi87 yeah i know that, i forgot to mention it. I will be using internal analog reference 1.1V.
    – Vasekdvor
    Nov 14, 2018 at 0:45

2 Answers 2


You should be using a P-channel MOSFET (which is set to be normally OFF with a pull-up resistor) and the Arduino is responsible for keeping it on:


simulate this circuit – Schematic created using CircuitLab

In this schematic M1 is normally off. You press and hold SW1 and the Arduino gets power. The first thing it then does is turn on the GPIO. That turns M2 on, which in turn pulls the gate of M1 LOW turning it on. You can now release M1 and the Arduino will stay on. When you want to turn off, just switch off the GPIO, turning off M2, which then allows R1 to pull the gate of M1 up again turning off the power.

This arrangement means:

  • You can control an incoming voltage higher than 5V (thanks to M2 doing the actual switching of the power MOSFET)
  • You get a soft-power switch to turn the power on
  • Current draw of the control circuit is basically the incoming voltage divided by the resistance of R1 (you can safely increase this if you want to reduce current draw - 1MΩ is fine).
  • You can have all the rest of the circuitry on the Arduino side of M1 so it has power removed when switched off (to prevent over-discharge of your batteries)
  • You are switching VCC, not GND (switching GND can cause all sorts of problems).
  • thanks, i got it, this works fine but i want to turn on arduino automaticaly (without switch) when the power is recovered. If we use a power supply (instead of battery). When there is a power cut to the power supply, its all meant to be automatically saved the data to memory (for powering atmega for this time, there is an supercapacitor), power down atmega and when the power is recovered, automatically power up atmega again and read the data and so on .......
    – Vasekdvor
    Nov 10, 2018 at 23:14
  • Sounds like you want a proper PMIC (or create one with a small MCU). Maybe thrown in a little 8 pin ATTiny to manage the power...
    – Majenko
    Nov 10, 2018 at 23:20
  • Personally I usually use a PIC10F200-I/OT in this situation. Really small, really low power, really cheap, really hard to program for with only 256 words of instructions and 16 bytes of RAM. Ideal for something like a simple PMIC though...
    – Majenko
    Nov 10, 2018 at 23:39
  • i think that i can't avoid it (using PMIC or any other special IC). I thought if it can be possible to create it with simple design, but i am worried that i really need to use special IC to do this thing.
    – Vasekdvor
    Nov 10, 2018 at 23:58
  • It is perfectly possible to create a circuit to do it, but that circuit would be considerably more complex with the addition of auto power on - and likely cost more than a PMIC or small low-power MCU. That's why PMICs exist - because they're cheaper and more convenient than trying to roll your own circuit.
    – Majenko
    Nov 11, 2018 at 0:17

It would be easier to simply to power down the CPU using software once you're ready to shut down:

  • Thank you, i know, but i don't want to sleep it, i want to completely turn off supply. I know that, you may ask why, but please just accept, that it will have to be like that.
    – Vasekdvor
    Nov 10, 2018 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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