Electrical – How to combine LED and voltage divider

arduinoresistorsvoltage dividervoltage measurement

I want to detect the presence of a 8.4V voltage source from an Arduino, so I'm using a voltage divider to step it down to a voltage safe for the Arduino to read with an digital pin.

However, for when the Arduino is powered off, I also want an LED to light when the voltage is present.

How do I combine these two circuits? So the divider didn't waste power, I was using high values 2/1M ohms, but I have to lower those if I want there to be enough current to power the LED. I calculated the maximum resistence needed to light a red LED would be around 400 ohms. Will this circuit work?

enter image description here

This circuit essentially sits "between" a battery charger and a battery, allowing an Arduino to detect when the charger has been attached.

EP (external power) goes to an Arduino digital pin.

S1 is a normally-open magnetic reed switch closed by a magnet on the input voltage source plug. I added it because Vin is attached to a battery's positive terminal, so that's there as a safety mechanism to ensure the 8.4V contact doesn't expose live battery leads when the external plug is unplugged.

D1 is necessary to keep EP pulled low when the magnetic plug closes S1 but no power is present, indicating the charger itself is unpowered.

Best Answer

Looks like it should work. You'll have about 8V at Vin, depending on the voltage drop across D1. That's fine since the Arduino's voltage regulator should handle that nicely.

You'll have about 4V at EP, a bit low for a 5V Arduino, but should work. If you have a 3.3V Arduino, that could be a bigger problem.

You'll have about 16.5mA going through the red LED, so if you're using one of the basic 5mm LED they usually have a max current of 20mA and a suggested current of between 16 and 18 mA. So perfect there.

However, if you wanted to use standard resistor values and get your EP voltage closer to 5V, you could do this. The current through the LED would be just over 17 mA, brighter, but still within suggested range.

enter image description here