Arduino Nano - Detecting Power Source

Hello everyone,

I need some help. I built a simple circuit that allows me to adjust the brightness of some IKEA LED Lights. You can see a demo below:

The LED’s require 12v of power to turn on. Since the Arduino didn’t have enough power to power them directly I built a simple circuit using transistors.

The Arduino is also powered from the LED’s power source (12v). So normally, when I unplug the LED’s then the Arduino turns off. However, when I have the Arduino plugged in using USB, then the Arduino keeps running even though the LED’s are off.

What I would like to know if when the Arduino is powered from the External Power Supply or from USB. I am sure this can somehow be done. However, I have no idea where to start…

I am a software guy, not a hardware guy :).

Any help is welcome.

Thank you.

You can use a voltage divider from the VIN pin on the 6-pin power connector to sense the VIN voltage. If it's 0, then you must be running from USB power.

A 10k resistor (from analog input pin to ground) and a 33k resistor (from analog input pin to VIN) would divide the VIN voltage by about 4 (0.232) prior to A/D sensing.

If you don't mind sharing, what action will you take based on the result?

Thanks RuggedCircuits! Works great!!

@EmilyJane

Its actually kind of useless; just mainly for learning purposes.

But now if the power if off (lights off because no power), once you turn them on I can transition them in (fade in).

The primary idea for this project was to be able to set the brightness of the LEDs.

Thanks again.

There is nothing useless about learning. Enjoy!