How to include an on/off switch

Good morning, Hope I have read enough of the FAQ to post a meaningful question.

I'm trying to turn a breadboard project into something thats actually useful and have a question about power and incorporating an on off switch.

I was plannign to use a battery bank type power supply (the ones you use for your phone etc) and connect it to my Uno via a USB cable as below (sorry for the appalling quality!!)

My question is where could i put a power on/off switch ( just a simple throw switch). Would i splice it into the power wire of the usb cable?

Thank you in advance for taking the trouble to read my question.

Power switches are usually placed on the +5v wire.

Note if your current draw form the battery bank is too small, circuitry in the bank may turn off the bank.

Thank you for your speedy response. So that would mean that i would have to open up the USB cable and add it to the red wire in that then.

I'm really sorry if i sound stupid but in all my other projects i've used a breadboard power supply which hasd a very obvious +5V wire. This is the first timeI'm attempting to make something portable, and that lack of wire +5V wire is confusing me!

Your project USB cable will plug into a USB jack on the project case.

This jack will have a 5v wire connecting the jack 5v pin to your project wiring.

It would be this wire that should be cut and have a power switch inserted.

I'm powering a few portable projects like You intend to do. I pull out one end of the USB cable to power them down... No extra stuff that might fail one day or the other...

Yes, but they cut off at different levels of current. Helpers once helped me to to arrange a timer pulling an output low. That output just draw som extra current. Works fine for one kind of packs but not for another. Trial and error....

Yes

Just making the OP aware of a possible problem.

Maybe post your circuit solution here ?

Why not? A 270 ohm resistor and some register code. I'll go digging.....

1 Like

I like the simple 270 resistor solution :wink:

Got the nucleolus here:

void setup()
// put your setup code here, to run once:
{
//1Hz 90% dutycycle  
  pinMode(9, OUTPUT);                               // Set digital pin 9 (D9) to an output
  TCCR1A = _BV(COM1A1) | _BV(COM1A0) | _BV(WGM11);  // Enable the PWM output OC1A on digital pins 9 and invert output
  TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS12);     // Set fast PWM and prescaler of 256 on timer 1
  ICR1 = 62499;                                     // Set the PWM frequency to 1Hz: 16MHz/(256 * 1Hz) - 1 = 62499
  OCR1A = 6249;                                     // Set the duty-cycle to 10%: 62499 / 10 = 6249

  delay(10);//allow pwm timers to start

Just add a 270 ohm resistor between pin 9 and GND.

Question to the OP, do you understand why and what @Railroader is doing ?

Nope not a clue.

I appreciate the help offered so far but I’m at a very basic understanding stage .... I have a sensor , I can get sensible output from it , I can display that output on an lcd screen. I thought a power bank would be an easy way to power it.

This looks like a rabbit hole I’m not ready for yet

Not really.

Your power bank may require you to take a minimum amount of current from it.

Many power banks will shut off (go to sleep) if this current is not taken by your circuit.

@Railroader 's code can be added to your sketch.

You would then add a 270 ohm resistor from Arduino pin 9 to GND.

Once a second, this resistor will take the minimum current that we are talking about and will keep the battery bank awake.



If more current is need we add a common 2N2222 transistor to pin 9 and use a smaller resistor value to draw more current.

Should be easy-peasy. :wink:

But USB chargers, if mains are available, don't have any surprising effects like that as far as I know. There are USB chargers running in cars, from 12 volt...

That's okey. Let's take one question at the time. What's the most interesting question right now?

So I understand that my power bank may switch off if my sensor And display combo don’t draw enough current to tell it that something is connected ...and I understand the code and adding the resistor will force a certain amount of current to be drawn to trick the power bank into being constantly on

What I’m still hazy is where to put a switch . I have a power bank .... it has a USB cable going from it to my Arduino. This will be internal in my project box

On the opposite side of the power bank I have a USB port that will be flush with the outside so I can plug it in to recharge via a different cable

My understanding is that I will need to open the USB cable that’s inside... find the red +5v wire and cut it and add the switch into it

I think???!

You think right.

Thank you, I genuinely appreciate the time people have taken to reply and point out potential issues .... along with solutions.

Now to crack out the soldering iron

They are terribly thin those cables... I cross my fingers.

Suggest you not cut open a USB cable, as mentioned the wires are very thin.