Power ON arduino Nano but only when USB port is in use

Is there a way to power ON arduino Nano but only when USB port is in use?

What I currently have set up:

  • A simple electronic board that drops 110v to 5v
  • I use this 5v as a USB port for charging cell phone.
  • Nano also uses this 5v and runs a 5v IV-9 vacuum tube.
  • A toggle switch to turn on and off Nano (manually)

What I would like to find out is... I would like to somehow detect when USB port is in use (cell phone charging) and at that time Turn ON Nano automatically (instead of a toggle switch)

Any help would be greatly appreciated.

Since the Nano is off you can't use it to detect the USB but maybe someone can help you setup sleep mode and interupts to wake it up using 5V from the charger to power the wake up circuit, which can vary in complexity. Alternately, a relay powered by the USB charger could be energized connecting power to the Nano by using the N.O. relay contacts and 5V from the USB charger connecting to Vcc of the Nano via the contacts.

I think I would not bother with turning off the Nano. That's probably not even want you want because I guess you just want to disable the display :wink:

So I would add a current shunt en measure the current to the device. And turn on the display if the current gets above a threshold.

If you’re going to do that you can use one of these.

Insert it between GND and the Nano GND, and then the voltage you measure will be GND referenced and you
won’t have to use differential mode to measure it. Whatever the voltage is on the end that is NOT connected to GND will be the current sense resistor voltage drop and the current is simply IRCS =VCS/RCS | Where “CS” = Current Sense
= VCS/0.1 ohms.

Thank you all for replying, I will give Current Sense Resistors a try, I'll post the outcome.

I have added the Current Sense Resistor. See image how I have things set up.

What happens now is that Nano is always ON, regardless if USB charger is in use or not.
I have absolutely no experience in electronics and I don’t speak the language.

I hope this makes sense to you,

The resistor is in the wrong place it is supposed to be IN SERIES (in between) the Nano GND and the 5V supply GND.

What happens now is that Nano is always ON, regardless if USB charger is in use or not.

Yes , of course. What did you expect ? The resistor simply provides a means of measuring current with the Nano analog input . This has nothing to do with shutting down the Nano other than to provide the necessary information (current) for use in a script that shuts down the Nano when the current exceeds some specified Value. To my knowledge, you have not provided us with your reason for wanting to shut down the Nano and the suggestion to buy the resistor was in response to the comment below to add a
current shunt to measure the current.

So I would add a current shunt en measure the current to the device. And turn on the display if the current gets above a threshold.

When you have corrected that error you need to :
Measure the voltage on the end of the resistor that is NOT connected to GND and use that to determine when to go into shutdown mode and then you need to decide on what the criteria is for waking up before you can write the Interrupt routine for waking up.

The voltage across the resistor will tell you the current , based on Ohm’s Law:
Icurrent sense resistor= Vcurrent sense resistor/Rcurrent sense resistor

IVcurrent sense resistor= Vcurrent sense resistor/0.1 ohm
ie:
Let Vcurrent sense resistor = 0.005 V (5 mV (1 analog count)
then I=0.005/0.1 =0.050 V (50 mV)

If you want to measure current less than 1 A you should replace the 0.1 ohm resistor with a 10 ohm

that will give you a voltage 10 times higher than the 0.1 ohm resistor , so the same example above
would give you a voltage of 0.005*10 = 0.05 V (50mV) (10 analog counts instead of 1).

For a 10 ohm resistor , the maximum current is 500mA (0.5A) because the voltage drop at that current
is 5V , which is the highest voltage you can measure with a 10 ohm resistor. If it is a 1W resistor, the maximum current you could measure would be 0.2A (200mA) , without exceeding the resistor power rating. With a 3W resistor, you could measure 500mA (2.5W).

By measuring the voltage, you can calculate the current and use that for determining when to shutdown
the Nano using code.

You might want to look at this tutorial on arduino auto-shutdown with relay