Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Arduino push button, Arduino turns itself off

Status
Not open for further replies.

robertbu

New Member
This is my first time on this forum and I'm not sure if it is the right forum or the right place on the forum. I'm trying to create a circuit so that an Arduino turns on immediately and stays after depressing a push button (S1). After that, the Arduino can turn itself off (by taking pin D6 high). Here is my failed attempt:

upload_2017-2-28_23-16-38.png

Without R3, the MOSFET was never turning off. Without R2, the circuit only latches after the code explicitly takes D6 low (after boot which takes a second) , but not before. With R2, the MOSFET latches on immediately, but does not turn off when D6 goes high. Any help would be appreciated.

The requirements are as follows:
  • The Arduino starts completely off, not in sleep or standby
  • On the press of a momentary push button, the Arduino comes on and stays on. After that, the push button does nothing as long as the Arduino is running.
  • At some future time, the code running on the Arduino can turn itself off. In the above circuit, it would bring pin D6 high.
I have several projects this circuit would be helpful for, but for different reasons. Here is one. Imagine a Magic 8 ball with a digital screen rather than the liquid and a 20 sided die. When the user picks up the 8 ball, a tilt sensor/ball switch makes contact and turns the Arduino on to display the info. When the Arduino senses that it is back face down for some period of time, it turns itself back off. In all likelihood, the ball will sit around for days or even weeks between uses, so there is no reason to use up battery by having the Arduino in sleep mode.

What I'm trying to do in the circuit above:

The MOSFET acts as a low side switch for the Arduino and the battery, so the 9V and 5V grounds are connected when the switch is pressed. When S1 is pressed, power goes to the Arduino and the MOSFET gate is turned on via the PNP transistor. With the MOSFET on, the Arduino stays on even after the push button is released. At some future time, the Arduino code brings D6 high turning off the MOSFET and therefore the Arduino. The circuit almost works. The problem is that D6 floats during the boot, so the circuit only latches after the code brings D6 low. Adding R2 (tried various values) keeps the pin from floating, but then for some reason, the MOSFET does not turn off when D6 is brought high.
 
Last edited:
Hi Robert
Your diagram is very unreadable. Please redraw it so people can understand it at a quick look.
If your ground of 9V battery connected to the ground of 5V and ground of your Arduino?
Regards,
EG

Edit: I read your description several times and still can't figure out what you are trying to do.
There are many helpful members who will be glad to help you with your project if they can understand your objective. Please elaborate and define your project in more details.
1- Are you trying to turn the Arduino itself on and off? What is the purpose of doing that?
With that concept in mind, how does the Arduino react to anything (like switch press) if it is off? Does it need to be on and perhaps on standby?
2- Or are you trying to turn on/off something else like an LED, motor, buzzer, relay,...so on
3- Is there a timing involved like a specific amount of time to do something after button press and then turn off?
 
Last edited:
I edited the question to add more info:

> If your ground of 9V battery connected to the ground of 5V and ground of your Arduino?

The switch and the MOSFET complete the connection of the 5V and 9V grounds. That is what allows the Arduino to turn on.

> Your diagram is very unreadable. Please redraw it so people can understand it at a quick look.

I'm a programmer with little EE experience. I don't know the standards or what you are looking for to make it more readable. If you can point out examples or standards, I'm willing to learn.
 
I can see why this layout is easier to read. Thanks. There is one difference. R2 ties to the ground of the Arduino in my circuit, not 9V ground. Are you suggesting that it should tie to the 9v ground?
 
It seems particularly confusing and difficult? :D It's rather strange switching the negative side of the battery, which doesn't help.

Here's a circuit that I've used a LOT recently, I 'stole' the idea from an AVR based component tester.

It uses two pins, one IN and one OUT - this allows you to switch the unit OFF by pressing the button, if you want to do so (or anything else you might want to use the button for, after it's powered up).

Momentary ON switch.GIF
 
Edit:
Actually, without the PIC running, I don't see how T1 gets turned on. Is it through the base at T3?

Thanks Nigel. The in and out is cool and simplifies an interface issue for another project. A few questions.
  • I can only see this working instantaneously if digital pin used for PIC out is pulled high by a resistor. Correct? If not pulled high, the pin floats and the behavior would be undefined until after boot which seems to take around a second on the Arduino.
  • What are you using for T1, T2, and T3 in your circuits?
  • I assume that R2, R3 and R6 are specific to the transistors used and the expected current draw?
  • What is the purpose of C1?
> rather strange switching the negative side of the battery

That's what happens when someone with only enough knowledge to be dangerous tries to design a circuit.
 
Last edited:
Hi Ian,
I too have stolen that circuit. I have used it in a battery operated light.

Hi robertbu, I was thinking of suggesting that circuit but realised that your code did not start running as soon as power was applied to the arduino. I have used it with an ATtiny13a running on it's internal 9.6 Mhz clock. the port that holds the power on is activated about 1 uS after power is applied.

Les.
 
Edit:
Actually, without the PIC running, I don't see how T1 gets turned on. Is it through the base at T3?

Yes.

Thanks Nigel. The in and out is cool and simplifies an interface issue for another project. A few questions.
  • I can only see this working instantaneously if digital pin used for PIC out is pulled high by a resistor. Correct? If not pulled high, the pin floats and the behavior would be undefined until after boot which seems to take around a second on the Arduino.

PIC's power up near enough instantly, as does an AVR - if your Arduino (which is just an AVR on a development board) is taking a second then there's possibly a problem somewhere?. Or does the Arduino perhaps wait to see if there's any bootloader instructions before it runs?.

The first thing my PIC program does is set the required pin as an OUTPUT, and sets it high to hold T2 and T1 both ON - there's loads of time (in PIC terms) to do this, while you're pressing the button.

  • What are you using for T1, T2, and T3 in your circuits?

Just general purpose NPN and PNP transistors - if you need any serious amount of current then make sure T1 is capable of it.

  • I assume that R2, R3 and R6 are specific to the transistors used and the expected current draw?

Not really, there's no great accuracy required - they all operate as switches - I think the values were the ones used in the original, but they aren't at all critical.

  • What is the purpose of C1?

I imagine it's for 'noise' prevention?, such as a brief low 'blip' out of the PIC not shutting it down.

Most of the units I've used this in do auto-shutoff, so you can either press the button to turn it OFF, or wait until it times out.
 
I edited the question to add more info:
I'm a programmer with little EE experience. I don't know the standards or what you are looking for to make it more readable. If you can point out examples or standards, I'm willing to learn.
This is a great Post by DERM on schematics. Although you might not follow all of its suggestions, you can make the attempt to improve on the schematics by being more aware: https://www.electro-tech-online.com/threads/rules-for-drawing-readable-schematics.144863/
 
Nigel Goodwin said:

PIC's power up near enough instantly, as does an AVR - if your Arduino (which is just an AVR on a development board) is taking a second then there's possibly a problem somewhere?. Or does the Arduino perhaps wait to see if there's any bootloader instructions before it runs?.​

All Arduinos I've used take about a second between the time power is applied to the time when the first line of my program is executed. I took a quick look at a couple of official bootloaders. On a quick skim, it appears that the bootloader does nothing but blink an led for 500ms, and then it makes a number (5 in one loader) tries to see if serial data is available (i.e. an Arduino sketch to be uploaded). I could modify or remove the bootloader to solve my issue, but it is not my preferred way to solve this problem. Your circuit and your comments are helpful as I try new things. Thanks.
 
I am still unsure as what the project suppose to do? SW wakes it up, then after certain amount of time, it will auto shut-down? And then waits for another SW press?
If yes, how long a delay?
Reminds me of the car headlight switch (or inside cabinet light). When engine is turned off, the lights stay on for a while and then turn off.
Then if the car is turn on, the headlights come on again and stay on.
 
Can you check the voltage on D6 when it being driven high ? I initialy thought the problem may have been that the ATmega328 was only being powered with 3,3 volts (which would mean the the output when D6 was high was only 3.3 volts so the 2N2907 would still have 1.7 volts driving the base.) I found the schematic of the Arduino nano and it shows that the ATmega328 is being powered from 5 volts so that is not the problem. D6 needs to be at least + 4.5 volts for the transistor to turn off. Can you also check the voltage on the gate of the FQP30N06L when D6 is high ? I have just noticed that when Ian has drawn R3 between the gate and source. (Which is where I would expect it to be.) On your schematic its is connected between gate and drain. (I don't understand the reason for connecting it that way.)

Les.
 
> EvilGenius wrote:
> I am still unsure as what the project suppose to do?​

It is all about battery savings. I have two VOM meters...a cheap one and a not so cheap one. I'm always forgetting to turn them off. The not so cheap one kindly turns itself off when it detects it is not being used. I have to press the 'on' button again to start it. In the case of my 8 ball example in my original post, the ball comes to life (tilt switch) when someone turns it over. They plays with it for a few minutes and then sets it down. The Arduino senses that it is not being played with anymore (continually in the face down position for some period of time) and turns itself off until the next time someone picks it up to play with. I don't want any visible switch, and I don't want to pay the battery price of having everything in sleep mode.

Les Jones wrote:​

I have just noticed that when Ian has drawn R3 between the gate and source. (Which is where I would expect it to be.) On your schematic its is connected between gate and drain. (I don't understand the reason for connecting it that way.)
It is between the gate and source on my circuit also. I don't know about the conventions in drawing a circuit, so the MOSFET is probably upside down in the drawing from what you expect.

D6 needs to be at least + 4.5 volts for the transistor to turn off.
I assume you are talking about the MOSFET? The datasheet for the FQP30N06L says that the max gate threshold voltage is 2.5V. How is the 4.5V calculated?

I'm away from my project for awhile. I'll make the voltage checks you ask about when I return. Thanks for helping me.
 
This a circuit that I use with a PICAXE microcontroller. It can be operated as Push-ON/Push-OFF and Push-ON/Program-OFF.

Ken
PicaxePowerSwitch00A.gif
 
The circuits provided, the feedback, and the questions have given me an answer about why my original circuit was not working. I've also developed a circuit that works, but I'm not completely comfortable with it.

What was happening with the original posted circuit:
  1. On startup D6 is pulled low by R2 and the circuit latches immediately
  2. The first line of code takes D6 low, which does nothing given R2
  3. Six seconds later the code pulls D6 high (to test turning itself off) and the power to the board is cut off as designed
  4. The voltage drops until it hits the brown-out point of the Arduino
  5. The Arduino reboots and therefore D6 is no longer held high
  6. R2 pulls D6 low again before the voltage regulator is full discharged
  7. The PNP transistor is again enabled which causes the MOSFET to reestablish power to the board
  8. Six seconds later, the cycle starts over again
The reboot was not obvious until I ran some tests.

Here is my redone circuit that does latch instantaneously and is turned off by bringing D6 high. It is a high-side switch this time given Nigel's comment:

upload_2017-3-1_22-9-27.png


The combination of Q1 and Q2 are self latching and work regardless of whether the Arduino is there or not. My two concerns:
  1. This design depends on D6 not being interpreted as high while it is floating during boot. It works for the Nano on my desk, but I cannot say that it would work on any arbitrary Arduino board.
  2. The value of R2 was set by trial, and I have no idea of the optimal value.
Feedback is appreciated, and thanks for what has been provided so far.
 
I assume that you have changed to a P channel mosfet. You could add a resistor of about 10K between the base and emitter of Q3 to ensure that it was switched off when D6 was floating. (This is probably not needed unless Q3 had a high leakage current.)
In post #15 I did mean that the voltage on D6 must be greater than +4.5 volts when it is high as the emitter of 2N2907A is at +5.0 volts so for the transistor to turn off the the base must be less than 0.5 volts negative of the emitter. The mosfet will not turn off until the transistor has turned off.

Les.
 
Les: Checking the voltage over time at the base of the transistors was the ticket to understanding the problem...something I should have been bright enough to do before posting the original question. I currently feel out of my depth designing my own circuits.

Quick question: Could I have solve the original problem by adding a capacitor and appropriate current limiting resistor to the D6 pin to extend the time the pin was high...and if so would that have been a good solution?
 
How about this:

Get the "Narcoleptic" (sleep) library for the Arduino. After doing whatever your program normally does, put the Arduino into a low-power sleep mode. The Library uses the Watchdog timer built-in to the Atmel processor to periodically "wake-up" the processor. Just write a program to put it right back to sleep again. If you turn off all of the optional hardware (ADC, UARTS, PWM) etc, you can get a 5V Arduino to draw only a few tens of uA while it is asleep. With the optional hardware turned off, it only draws ~1mA while it is awake. It only has to be awake for a few ms before you put it back to sleep again. This should extend the battery life to where you dont actually have to completely remove power from it...

I have done this to create a long term timer, where I wanted very low power drain while inactive. The watchdog "wakes up" the processor after selectable periods.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top