# Help choosing switch for on/off timed circuit

I'm a beginner so sorry for such a simple question. I have a microcontroller connected to a 5V powerbank. I need a circuit to switch everything off 10 seconds after the press of a button. To turn it on, another button is used to reactivate the circuit. The code is no problem for me, I'm just struggling with the circuit.

I made a simple schematics with my idea, it's just missing the correct switch (S2). I tried with a relay, but with no success. Maybe a transistor could do the job, but I'm not sure how to use a transistor to switch off the positive lead and what type I should use.

Please see the image below, any help will be appreciated!

• I tried with a relay, but with no success. Then you're not doing that correctly, look at the many schematics which turn up when Googling for "microcontroller relay circuit" and then look at the image results (not the websites). That will show many circuits of how to do this. Try to understand those. Try to understand why a transistor is needed. Try to understand what kind of relay you need. Trying and failing is OK, what you need is understanding and knowledge. The internet is packed with those so get searching, reading and learning. – Bimpelrekkie Sep 27 '16 at 13:16
• Well, I think I know what happened when I tried a relay. I know how it works and I can turn things on/off with a relay, but in this case, when you switch the relay, it switches back on instantly because you stop providing power to the relay which also moves the coil. So it doesn't turn off. In relation to transistors, I know the basics, like sending a high voltage to the base which connects the 2 sides. But I have no idea how to send voltage to the base and do the opposite. I thought someone could give me a quick hand here. – Chu Sep 27 '16 at 13:24
• Then reverse the operation so that the relay coil is powered to activate the micro. – Andy aka Sep 27 '16 at 13:32
• Almost all relays have 3 contacts per switch so you can also use it to switch on to keep the power. Power the electronics such that the power is on when the relay is on. You probably bypass the switch only when you turn off the switch S3, that is not a good approach. Forget about transistors because if you already have trouble with switches and relays you're by far not ready to use a transistor. – Bimpelrekkie Sep 27 '16 at 13:33
• I tried all this, it just doesn't work. Maybe I'm using the wrong type of relay... It's a Songle SRD-05VDC. I reversed the operation, powering the MCU from the relay output. Still, when I activate the S1, it just doesn't move (or makes a weird noise when the control is connected straight to 5v). – Chu Sep 27 '16 at 14:21

Thanks for your reply. I guess I may not fully understand your writing and you didn't fully understand mine. So I may as well write up an answer to see if that helps improve communication and make it more concrete.

You said this is an Arduino, that it is driving other things, and that you figure you may need $1.0-1.5\:\textrm{A}$ from the power supply. Also, you obviously have considered a relay, mentioning specifically the Songle SRD-05VDC. But by the time you add the external parts to operate the relay, you may be better off just using a PMOS:

simulate this circuit – Schematic created using CircuitLab

If $SW_1$ bounces, your Arduino may wind up getting locked up in the process of starting. But adding debouncing externally complicates things, as $SW_1$ and $D_1$ are actually supplying power and the current may be over an amp, you said.

I'm ignoring the minimum $V_{CC}$ of your Arduino. $D_1$ drops a voltage and $V_{CC}$ may not meet specs after that drop. You could replace it with an appropriately sized Schottky and try that.

Regardless, your MCU is responsible for getting $P_1$ activated quickly so that it can pull down on the PMOS gate and keep the power applied. Your MCU would also monitor $SW_2$, of course, and then wait out the necessary delay before releasing it's hold-down of the PMOS via $P_1$.

The following circuit provides the needed timing, externally:

simulate this circuit

Again, you use a momentary pushbutton, $SW_1$, to turn on the power. The circuit starts counting down time, then. Once your MCU is running, it activates $P_1=1$ and this holds the circuit active. You monitor $SW_2$ via $P_2$ (which you need to configure with an internal pull-up, if possible, and an external pull-up resistor, if not possible) for the shut-down command using software you write. When your MCU detects that there is a shutdown in progress, the MCU causes $P_1=0$ (or high impedance) and this then will allow the timer circuit to start counting back down towards a shutdown of the MCU. Then the power is completely removed and everything is back to the way it was, once the time-out takes place.

The MJE170 should be large enough to handle your load and I've set $R_1$ and $R_2$ to be small values based on the need for a lot of base drive current for $Q_1$. Probably could get rid of $D_2$. $D_1$ provides a path for current from $C_1$ when $Q_1$ turns off. But you might be able to get rid of that for your needs, too (forcing the charge to decay out via $R_3$ instead.)

You might say, "Well, I don't want all that external timing stuff." Okay:

simulate this circuit

You have a debounced switch and your micro controls the timing.

• Great answer! Thank you very much, I will try these circuits. – Chu Sep 28 '16 at 12:01

You may consider leaving the uC on all the time drawing uA of current only and use one (1) momentary switch to toggle a software controlled output OFF with X delay and ON with no delay.

If relay coil uses more than 10mA then drive with Nch "logic level" FET gate high to drive on low side of a relay coil for Positive Logic 1= ON.

Alternatively 2 momentary input switches or a latched SPST switch to ground with a pullup R can be used as input.

The power on state or 1st connection state should be defined by design and all switches have contact debounce included by software filter or small Cap filter.

simulate this circuit – Schematic created using CircuitLab

Can't you just use sleep mode like everyone else?

• The relay is $90\:\textrm{mA}$. – jonk Sep 28 '16 at 1:39
• I see now or 71.4 – Tony Stewart Sunnyskyguy EE75 Sep 28 '16 at 2:08
• Thank you, I will try your suggestions. I was avoiding sleep mode because I also need to stop other components (such as a Raspberry PI) which are also being powered by the power bank. – Chu Sep 28 '16 at 12:07