# detect voltage by arduino

I've wired simple circuit with 9V battery, red LED, 10K resistor to turn the light on.

And I'd like to know if the LED is lighting or not using arduino.

I simply wired Arduino's A0 pin and LED's + lead. Next, if I get value from A0 using analogRead() function, it returns 0 always. If I just read from A0 without wire, it returns random values(I don't know it's random or not, anyway, it seems to be irregular).

Question: How can I know external circuit's LED is lighting or not using Arduino?

PLUS

the question is related with this question

I've tested following schematic(sorry for its poor drawing)

4 digits display ----- 4N35(PIN 1)
ㄴ---------- 4N35(PIN 2)

ARDUINO 5V ----------- 4N35(PIN 5)
GND ---------- 4N35(PIN 4)
A0 ----------- 4N35(PIN 4) <--- This is the goal


If I place LEDs for each side, it works well.

The problem is, the voltage I've measure from 4 digits display is too low as around 0.14. So, it may be the reason 4N35 doesn't emit any signal I think(If I turned the power on of portable range, Arduino side LED is turned on for a moment).

Okay, Question again please !!! I'd like to know the state of portable range and my trying is figuring out which LED is lighting from the 4 digits display. But, 4N35 could not catch its voltage(not sure tho). How can I do this? Any comment will be helpful.

• Can you add schematic for clarification? – Justin Trzeciak Nov 8 '14 at 0:59

I am assuming you are going to simply measure the voltage drop across the LED and use that to determine if the LED is on, this will work but you will need a couple of extra components, you can damage your arduino if you feed in a voltage over 5V.

simulate this circuit – Schematic created using CircuitLab

In the above R1 and R2 form a voltage divider to reduce the voltage on the A0 pin of your arduino. We can calculate the maximum voltage you can use to safely stay under 5V on A0:

Vmax = 5.0 / (R2 / (R1 + R2))
= 5.0 / (47000 / (100000 + 47000))
= 15.6V


Finally read the value of A0 in your arduino code and use the following formula to convert that value into a voltage:

float r1 = 100000;
float r2 = 47000;

float vRaw = (analogRead(0) * 5.0) / 1024.0;
float vDrop = vRaw / (r2 / (r1 + r2));


Depending on the accuracy needed you may need to mess with the 5V value above and adjust r1/r2 to a measured value (depending on accuracy of the resistors you are using).

For a complete example see https://www.udemy.com/blog/arduino-voltmeter/

• wont the value read at A0 will always be the same? Since V+ is referred? – Umar Aug 4 '16 at 12:27

You could use a photoresistor.

           PhotoR     10K
+5    o---/\/\/--.--/\/\/---o GND
|
Pin 0 o-----------


http://playground.arduino.cc/Learning/PhotoResistor

• okay, but, what if there're pretty many LEDs and they're very close each other? how can I get which LED is lighting? – Hongseok Yoon Nov 6 '14 at 3:19
• If they're on the same wire, if one lights the others should too.. – hanoo Nov 6 '14 at 3:23
• You can mesure the voltage of the circuit using a voltage divider to know if the battery is good enouth. – hanoo Nov 6 '14 at 3:25