How to Make Auto Power OFF Circuit with Arduino?

20 kg load cell
Written by Indrek Luuk

Table of content:

  • Arduino Self Power OFF Circuit.
  • How to Read the Power Button Status in Your Code?
  • Can You Build a Self Power OFF Circuit with One MOSFET?

The charge of a battery is limited. It would be nice if your battery-powered device could power itself OFF if it has been idle for some time.

With a couple of MOSFETs and some resistors, you can create a circuit that makes it possible for your Arduino to use a Digital Output pin to shut itself OFF.

In this article, I am going to explain step-by-step how to make the connections. First, let's make the basic connections, and then optionally, we can add some wires to read the push button status in your Arduino code.

DFPlayer Mini connection diagram

Required Components

Optionally, if you want to read your power button status from a Digital Input pin you also need:

Disclosure: Bear in mind that some of the links in this post are affiliate links and if you go through them to make a purchase I will earn a commission. Keep in mind that I link these companies and their products because of their quality and not because of the commission I receive from your purchases. The decision is yours, and whether or not you decide to buy something is completely up to you.

Arduino Self Power OFF Circuit.

Schematic for Arduino self power off circuit

The power source has to be 7 to 12 volts. We are going to connect it to the Vin pin, and the on-board voltage regulator needs it to be at least 7V to work reliably.

1. Connect the P-Channel MOSFET between the Arduino Vin pin and the positive output of the power source.

The Drain terminal goes to the Vin pin and the Source to the positive side of the power supply.

This MOSFET is the main power switch.

2. Connect the negative output of the power source to the Arduino GND pin.

3. Add a 10k pull-up resistor between the Gate and Source terminals of the P-Channel MOSFET.

The MOSFET will be in the OFF state if the voltage between Gate and Source is 0V. This pull-up resistor ensures that the power is switched OFF while neither the button or Arduino D7 pin is active.

4. Connect a push-button between the Gate and the GND.

Now you can try it. If you hold down the button, Arduino will turn ON. At this stage, it will turn OFF immediately when you release the button.

5. Put an N-Channel MOSFET between the Gate terminal of the P-Channel MOSFET and the GND.

The Drain terminal of the N-Channel MOSFET goes to the Gate of the P-Channel MOSFET. The Source of the N-Channel MOSFET to the GND.

This is the secondary MOSFET that acts as a switch for the Arduino output pin to pull down the Gate of the main power MOSFET.

6. Add a 10k resistor from the Gate of the N-Channel MOSFET to the GND.

This resistor ensures that the N-Channel MOSFET is turned OFF while Arduino is powered OFF.

7. Connect the Arduino digital output D7 pin to the N-Channel MOSFET's Gate via a 100-ohm resistor.

The 100-ohm resistor is necessary since the MOSFET will have a small internal capacitance. When you switch the digital output pin, it will start to charge/discharge, and it will create a current spike that can damage the Arduino Arduino pin, especially if you plan to do high-frequency switching.

The wiring part is now done. But if you try it now, it will still switch off immediately after you release the button.

8. Finally, you need to activate the Digital Output D7 to keep the power ON after the button is released.

void setup() {
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
}

When you power up the Arduino, it takes about two seconds for your code to run. It's the time that Arduino bootloader waits for a new program to be loaded to the controller.

This boot-up delay means that you have to hold the button for about two seconds. If you release it too early, then it will shut down immediately. If you keep it down a couple of seconds, then it will stay ON.

To shut down the Arduino from your code, you have to set Digital Output D7 to LOW.

This code will shut down the Arduino 5 seconds after start-up:

void loop() {
  delay(5000);
  digitalWrite(7, LOW);
}

How to Read the Power Button Status in Your Code?

You may want to read the power button status while the device is running. For example, if you also want to use it as the OFF button.

To make this possible, you have to modify the circuit a little.

Schematic for Arduino self power OFF circuit with power button input pin

1. Add a diode between the Push Button and the Gate of the P-Channel MOSFET.

This diode is necessary to prevent the N-Channel MOSFET from pulling down the D10 signal if D7 is active. We only want the D10 pin to be pulled down by the button.

2. Add another diode to the Push Button in parallel to the first diode.

The second diode is to protect the D10 pin from the voltage coming from the power source. It can be 7 to 12 volts. Arduino pins are not designed to handle that.

3. Connect a wire from a Digital Input pin to the second diode.

4. Initialize the Digital Input D10 pin with INTERNAL_PULLUP.

void setup() {
  pinMode(10, INPUT_PULLUP)

  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
}

Now, if the button is pressed then it will also pull down the signal from D10.

Below is an example program. After boot-up, it will start counting down from 5 seconds. If you press the button while it is running, the 5-second timer will reset, and the on-board LED will blink. If you release the button, it will continue counting down, and it will shut itself down if the time is up.

long shutdownTimer = 0;

void setup() {
  // initialize pin 13 as output 
  // to blink the on-board LED
  pinMode(13, OUTPUT);

  // initialize the button status pin
  pinMode(10, INPUT_PULLUP);

  // hold the power mosfet ON
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
}

void loop() {
  // wait for the shut-down timer
  while (millis() - shutdownTimer < 5000) {
    // if the button is pressed 
    // (pin 10 is pulled to ground)
    // then extend shutdownTimer
    // and blink the on-board LED
    if (!digitalRead(10)) {
      shutdownTimer = millis();
      blinkLed();
    }
  }
  // when the time is up then shut it down
  digitalWrite(7, LOW);
  // give it time to shut down
  delay(1000);
}

void blinkLed() {
    digitalWrite(13, HIGH);
    delay(200);
    digitalWrite(13, LOW);
    delay(200);
}

Can You Build a Self Power OFF Circuit with One MOSFET?

No.

You can't use a single MOSFET since you will get a current leakage through the pull-up/pull-down resistor connected between the Source and the Gate.

A simple attempt at the circuit with only one MOSFET:

Current leakage if only one MOSFET

If this resistor has a very high value, then the current flowing through it would be minimal. But the voltage drop across it can be steep enough to turn the MOSFET partially ON. If the resistor has a small enough value so that the MOSFET is OFF, you will get higher current flowing directly through the resistor.

With a single MOSFET, you will never get your circuit to be completely OFF.

You need the second MOSFET to isolate the Arduino IO pin from the power source. If you use an N-Channel MOSFET to disconnect the positive wire, then you have to separate your IO pin from the positive output of the power source. If you are using a P-Channel MOSFET to disconnect the negative wire, then you have to isolate your IO pin from the negative output of the power source.

Leakage fixed by adding a P-Channel MOSFET on the D7 wire:

Current leakage fixed with a second MOSFET

哆哆女性网2014年属马女孩起哪个名字解梦怎么测试起个甲醛公司的名字网站推广seo软件西安购物网站建设好的园林设计网站国债逆回购周末交易吗tvb最新电视剧 下载中国教师资格网cad转换成pdf网页优化和网站推广退休申请周易起名软五格起名可信吗php网站建设培训万古丹帝战神2玄起名电商平台网站制作宁氏宝宝起名起名男人鸿字一般网站制作多少钱特别伤感的句子说说心情守望者加速器姓属鼠的宝宝起名大全绝密543电视剧全集完整免费版辽源网站排名优化原版周公解梦梦见树随州seo招聘给男宝宝起英文名字淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻不负春光新的一天从800个哈欠开始有个姐真把千机伞做出来了国产伟哥去年销售近13亿充个话费竟沦为间接洗钱工具重庆警方辟谣“男子杀人焚尸”男子给前妻转账 现任妻子起诉要回春分繁花正当时呼北高速交通事故已致14人死亡杨洋拄拐现身医院月嫂回应掌掴婴儿是在赶虫子男孩疑遭霸凌 家长讨说法被踢出群因自嘲式简历走红的教授更新简介网友建议重庆地铁不准乘客携带菜筐清明节放假3天调休1天郑州一火锅店爆改成麻辣烫店19岁小伙救下5人后溺亡 多方发声两大学生合买彩票中奖一人不认账张家界的山上“长”满了韩国人?单亲妈妈陷入热恋 14岁儿子报警#春分立蛋大挑战#青海通报栏杆断裂小学生跌落住进ICU代拍被何赛飞拿着魔杖追着打315晚会后胖东来又人满为患了当地回应沈阳致3死车祸车主疑毒驾武汉大学樱花即将进入盛花期张立群任西安交通大学校长为江西彩礼“减负”的“试婚人”网友洛杉矶偶遇贾玲倪萍分享减重40斤方法男孩8年未见母亲被告知被遗忘小米汽车超级工厂正式揭幕周杰伦一审败诉网易特朗普谈“凯特王妃P图照”考生莫言也上北大硕士复试名单了妈妈回应孩子在校撞护栏坠楼恒大被罚41.75亿到底怎么缴男子持台球杆殴打2名女店员被抓校方回应护栏损坏小学生课间坠楼外国人感慨凌晨的中国很安全火箭最近9战8胜1负王树国3次鞠躬告别西交大师生房客欠租失踪 房东直发愁萧美琴窜访捷克 外交部回应山西省委原副书记商黎光被逮捕阿根廷将发行1万与2万面值的纸币英国王室又一合照被质疑P图男子被猫抓伤后确诊“猫抓病”

哆哆女性网 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化