running 3v voltage through Vin pin while powering arduino with usb port

I’m trying to create a system that essentially is connected to a power adapter running at 3v being sent to the Vin port, and a power bank supplying 5v to the USB jack (whilst having the power bank charging)

Essentially, I have the actual Vin pin on the arduino board connected to a small voltage divider circuit which sends the divided voltage into an analog in pin. Essentially what im trying to do is on the event of a power outage i want the arduino to detect the fact that the power has gone out and start running a secondary goto loop section of code that would essentially act as a “low power mode program” embedded into the main program. what i’m wondering if while the arduino is being powered via the USB port, i want to know whether i can send a voltage less than 3v into the Vin port while its being powered by the USB port, keeping in mind of course that at ~5-6v it the arduino board automatically switches from the Vin port to the USB port.

I’ve been doing a lot of research and digging online but I’ve found nothing. So is what i’m describing safe for the arduino or will it harm it in some way?

20-year hardware designer here. It sounds like you simply need a buck regulator with a "power good" indicator. There are a lot of switch-mode power supply ICs that have programmable "fault" trip voltages, that give a simple open-collector discrete output. You want to use a SMPS because even at low efficiency (since you probably aren't drawing much current) you're "throwing away" less power than with a linear regulator or certainly less than a resistor divider (which you should really never do for a supply input).

Since you mention power outage, I assume that means you have a battery backup. There are "rail switchers" which are "ideal diode" circuits that use MOSFETs and ideal diodes to "diode OR" two power sources; the USB power rail gets priority and is the main source of current, but if that power goes away, the deivce switches to battery backup automatically. Those also have a power state digital output that tells you whether you're on USB power or on battery power.

Does any of that sound like what you're looking for?

Well let me show you a general idea of the circuit and the code that would work with it:
Img Link

the code would look a little something like this:

loop:

digitalWrite(IO0, LOW); //pretend that IO0 was initialized and added in setup at start of program

power = analogRead(0);

if (power < 100) {

  ;goto powerout;

  powerout:

  digitalWrite(IO0, HIGH); //pretend that IO0 was initialized and added in setup at start of program

  // **insert power outage program here)**

  if (power > 100) {

    ;goto loop;

  }

  else {

  ;goto powerout;

  }

}

// **main program loop here**

;goto loop;

I know that the Vin plug on the arduino requires a minimum 6v to operate the arduino, im just wondering if a voltage less than imputed while the arduino is running off of the USB port (at 5v of course) will hurt the arduino in some way? if it wont then my idea that i have in mind will probably work, sorry about the really confusing explanation here, this is one of things that i got perfectly lined up in my head but i just have trouble putting into writing

If you connect a 3v source to a 5v source (the Arduino Vin pin) then current will try to back feed from the Arduino into the 3v source.

Make sure to put a diode in the line to prevent that. And note that a diode will drop about 0.6v of your 3v source.

You have not said what Arduino you are using but a separately, a 16MHz Atmega 328 (as in the Uno) will not work on 3v. The clock rate must be lowered to 8MHz for 3v to work.

...R

Thank you, your answer was quite helpful, I'm using an arduino Uno, sorry for not specifying.
I will make sure to put a diode before the first resistor on the voltage divider leading into the analog in pin to prevent back flow. Thank you! also a 0.6v drop doesn't fully matter, i just wish to use that small voltage as the voltage that the arduino is looking for when looking to see if the power is on. Thank you for the help!

Ghostcrafter090:
Thank you, your answer was quite helpful, I'm using an arduino Uno, sorry for not specifying.
I will make sure to put a diode before the first resistor on the voltage divider leading into the analog in pin to prevent back flow. Thank you! also a 0.6v drop doesn't fully matter, i just wish to use that small voltage as the voltage that the arduino is looking for when looking to see if the power is on. Thank you for the help!

I'm confused.

Do you just want the Arduino to detect if the 3v power supply is ON?

If so I don't understand the role of the Vin pin?

...R

Essentially i'm unable to run the adapter line directly to the analog pin. so i'm trying to run it through the Vin port instead and then intern connecting the Vin pin to the analog in and have it to detect it that way.
(keeping in mind that i do this while the board itself is being powered by the USB port at 5v). The reason why i think this might work is that if you are sending power into the Vin port, you can then draw that same power from the Vin pin on the board, so essentially i'm just connecting that to analog in and having the code detect when whatever is coming through there stops coming through (caused by for example a power outage) and switch to a different section of the program.

Ghostcrafter090:
Essentially i'm unable to run the adapter line directly to the analog pin. so i'm trying to run it through the Vin port instead

That makes no sense to me.

And it does not answer the question I asked in Reply #5

...R

Ghostcrafter090:
I'm trying to run it through the Vin port instead and then intern connecting the Vin pin to the analog in

Not possible. Vin is not directly connected to the atmega.

Robin2:
That makes no sense to me.

I agree.