0
\$\begingroup\$

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!

timer on/off switch with MCU

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Bimpelrekkie Sep 27 '16 at 13:16
  • \$\begingroup\$ 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. \$\endgroup\$ – Chu Sep 27 '16 at 13:24
  • \$\begingroup\$ Then reverse the operation so that the relay coil is powered to activate the micro. \$\endgroup\$ – Andy aka Sep 27 '16 at 13:32
  • \$\begingroup\$ 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. \$\endgroup\$ – Bimpelrekkie Sep 27 '16 at 13:33
  • \$\begingroup\$ 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). \$\endgroup\$ – Chu Sep 27 '16 at 14:21
1
\$\begingroup\$

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:

schematic

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:

schematic

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:

schematic

simulate this circuit

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

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Great answer! Thank you very much, I will try these circuits. \$\endgroup\$ – Chu Sep 28 '16 at 12:01
1
\$\begingroup\$

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.

schematic

simulate this circuit – Schematic created using CircuitLab

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

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ The relay is \$90\:\textrm{mA}\$. \$\endgroup\$ – jonk Sep 28 '16 at 1:39
  • \$\begingroup\$ I see now or 71.4 \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Sep 28 '16 at 2:08
  • \$\begingroup\$ 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. \$\endgroup\$ – Chu Sep 28 '16 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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