# Need help about detecting broken led.

First of all , I'm new arduino and ive been studying it for a while now..

Kindly please help me, I've been working on this project wherein i need to know if its a led(bulb) is broken? Now I don't know how will I program it, i need a mechanism to which can detect if the led is installed or not or is it broken?

I need some ideas..
Thanks

Disclaimer: my electronics knowledge is rusty.

Measure the voltage over the led using an analog input. If the led is supposed to be on, a current will flow resulting in a voltage that you can measure.

E.g. Vcc to ressistor; other side of resistor to positive side of led; negative side of led to ground. Measure voltage at the junction of resistor and led.

5V -> no current, led broken (open)
0V -> led shorted
1.2V (or whatever the led forward voltage is) -> OK

Note that a broken resistor will cause misreadings.

Alternative: constant current source (replacing the resistor) and measure voltage over led.

sterretje:
Disclaimer: my electronics knowledge is rusty.

Measure the voltage over the led using an analog input. If the led is supposed to be on, a current will flow resulting in a voltage that you can measure.

E.g. Vcc to ressistor; other side of resistor to positive side of led; negative side of led to ground. Measure voltage at the junction of resistor and led.

5V -> no current, led broken (open)
0V -> led shorted
1.2V (or whatever the led forward voltage is) -> OK

Note that a broken resistor will cause misreadings.

Alternative: constant current source (replacing the resistor) and measure voltage over led.

Thanks for the reply and for the idea. Is there any way your could tell the syntax for that measurement of voltage since am new to arduino I'm still learning the syntax.

sterretje:

well ive tried that one and all i get is 0, even the led is on or, misplaced.

``````int led = 4;
int led2 = 3;
int val = 0;

void setup() {
// initialize the digital pin as an output
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);

}
void loop(){

Serial.println(val);
delay(2000);

}
``````

This indicates that the LED is on digital pin 4:-

``````int led = 4;
``````

This reads analogue pin 4, (A4):-

``````val = analogRead(4);
``````

Did you connect A4 to D4? Show how you connected things with a simple schematic diagram.

Even if you connected things correctly, since you only make the LED pin an output, (default LOW), you would read 0. Your code never makes it HIGH.

You'll need a pulldown resistor on the analogue pin, (maybe 10K or larger), so that when the LED is removed or open-circuit, the result of an analogue read will be guaranteed to be about 0.
Ignore this - a dumb moment on my part.

You can not use analogRead() on pin 4; you need to connect the junction of resistor and led to an analog pin (A0 .. A5 on an Uno) and read the pin with that name

``````val = analogRead(A0);
Serial.println(val);
``````

If you still have problems, show your schematic (a real one or a a photo/scan of a hand-drawn one). With a simple circuit like this, I think a photo that clearly shows the wiring will do.

This is more or less how you want to connect it:-

The value will be close to 1023 if the LED is missing, below about 250 if it's OK.
Edit: Oh, and about 0 if the LED is short-circuited, as sterretje says.

How bout this one. This is my scheme, sorry am no engineering student, am just curious about arduino.

How bout this one. This is my scheme, sorry am no engineering student, am just curios about arduino, thats why am having a hard time understanding schemes.

Definitely not. You have the LDR directly across the 5V rail. And you don't connect anything to an analogue input, which would be necessary.

You don't need an LDR to tell if an LED is installed/dead. Just sterretje's method, as shown in the diagram in reply #7.

How bout this one. This is my scheme, sorry am no engineering student, am just curious about arduino.

Does not work. Look at what I described and /or what OldSteve showed.

For my description:
Do not connect the red wire to A4 but to Vcc.
Add a new wire from A4 to the junction of the LED and the resistor.

OldSteve:
Definitely not. You have the LDR directly across the 5V rail. And you don't connect anything to an analogue input, which would be necessary.

You don't need an LDR to tell if an LED is installed/dead. Just sterretje's method, as shown in the diagram in reply #7.

well Yes. Its just that i haven't read all the reply,before posting mine. I have change my wirings from digital to analog pins, and Im getting a value. Instead of 1 to 5v, am getting 923 when the led are on, the ldr there is for another purpose, there another code for that one, I just think that posting all the codes is unnecessary. How could i change that value? for volts. Where do i connect my ldr?

What sterretje said.

If you really want to use an LDR just for the sake of practice, connect it as below:-
(You might need a different LDR resistor, but 10K is a good starting point.)

Edit: You posted as I was typing. Anyway, this diagram shows how you should connect an LDR. The earlier one shows how you can tell if a LED is connected without using an LDR. Of course, neither serves any real purpose. An LED is unlikely to blow, or to suddenly disappear, so I assume this is all just a practice exercise, unless you want to monitor an LED in another circuit, but I guess if that's the case you would have said something to that effect.

OldSteve:
What sterretje said.

If you really want to use an LDR just for the sake of practice, connect it as below:-
(You might need a different LDR resistor, but 10K is a good starting point.)

Edit: You posted as I was typing. Anyway, this diagram shows how you should connect an LDR. The earlier one shows how you can tell if a LED is connected without using an LDR. Of course, neither serves any real purpose. An LED is unlikely to blow, or to suddenly disappear, so I assume this is all just a practice exercise, unless you want to monitor an LED in another circuit, but I guess if that's the case you would have said something to that effect.

Well, am still trying to figure that out. Anyways I got it running though. I've heard that the high resistor you use the less voltage you get. Why is that ive used different resistors from my leds and they still have the same output. Plus do i need to repeat this code on every led ive installed? Is there any other syntax to lessen the code.

``````int led = A2;
int led2 = A4;

int val = 0;
int val2= 0;
float voltage;
float voltage1;

void setup() {
// initialize the digital pin as an output
Serial.begin(9600);
pinMode(led, INPUT);
pinMode(led2, OUTPUT);

}

void loop(){

voltage = val *(5.0/1023.0);//here's the code to get voltage
Serial.println(voltage);
}
``````

In both cases (led and ldr) you create a voltage divider. For the led, that divider however has a constant voltage due to the intrinsics of the led.

Your led has a constant forward voltage (e.g. 1.2V). The resistor is there to limit the current and the bigger the resistor, the lower the current and hence the intensity. The resistor will not have an effect on the voltage (till you make it far too big).

For the LDR, you create variable voltage divider. The voltage that you measure depends on the resistance of the LDR which in turn depends on the amount of light on it.

The formula (for OldSteve's schematic in reply #12):

``````Vmeas = Vsupply x Rldr / (Rldr + 10k)
``````

where Vmeas is the measured voltage, Rldr is the resistance of the ldr and Vsupply is the supply voltage.

sterretje:
In both cases (led and ldr) you create a voltage divider. For the led, that divider however has a constant voltage due to the intrinsics of the led.

Your led has a constant forward voltage (e.g. 1.2V). The resistor is there to limit the current and the bigger the resistor, the lower the current and hence the intensity. The resistor will not have an effect on the voltage (till you make it far too big).

For the LDR, you create variable voltage divider. The voltage that you measure depends on the resistance of the LDR which in turn depends on the amount of light on it.

The formula (for OldSteve's schematic in reply #12):

``````Vmeas = Vsupply x Rldr / (Rldr + 10k)
``````

where Vmeas is the measured voltage, Rldr is the resistance of the ldr and Vsupply is the supply voltage.

I'm having a hard time understanding terms, kindly put them up into your Layman's term if possible if not, ill be doing the best i can to understand it. Anyways so you mean it doesnt vary at all what resistors to use.

pjaypabs:
I'm having a hard time understanding terms, kindly put them up into your Layman's term if possible

No. You need to learn the correct terms. We shouldn't have to come up with another way of describing things.

If you don't understand a term that's used, do yourself a favour - Google it or otherwise look it up.

ie. Google "voltage divider" if you don't understand it. If you're unsure what "forward voltage" means with respect to LEDs, check out an LED datasheet, particularly looking at Vf.

If you don't understand the formulae, Google "Ohm's Law".

etc

etc

Edit: This covers the basics of LEDs:- Light-Emitting Diodes (LEDs)

OldSteve:
No. You need to learn the correct terms. We shouldn't have to come up with another way of describing things.

If you don't understand a term that's used, do yourself a favour - Google it or otherwise look it up.

ie. Google "voltage divider" if you don't understand it. If you're unsure what "forward voltage" means with respect to LEDs, check out an LED datasheet, particularly looking at Vf.

If you don't understand the formulae, Google "Ohm's Law".

etc

etc

Edit: This covers the basics of LEDs:- Light-Emitting Diodes (LEDs)

Is that so, am sorry it's just I conclude that if you make them simpler, I can reply fast cause i understand them, but am taking too long to reply cause I've been busy searching them.. My bad though. Anyways ill be back tomorrow cause ill be doing other things for now. Thanks again for the help. Anyways I've learned alot today.

Well okay i'll be studying for now.. I'll be back if i have questions. Thanks.

pjaypabs:
Is that so, am sorry it's just I conclude that if you make them simpler, I can reply fast cause i understand them

If we had to fully explain every two-word term, we'd be here forever. Much better if you use this as an opportunity to learn. (No need to be sorry. )

Another thing that's well worth spending some time on is learning how to read and draw schematic diagrams. There's no need for Fritzing-style diagrams, and they don't convey anywhere near as much information as a good schematic diagram. (Less chance of silly mistakes, too.)

This might help:- How to Read a Schematic

Here is a whole different idea.
Pulse the LED as if it were a cap,
Read it as if it were in input and see how long it takes to decay to change state.
do this in set-up as you only need to do it once in every great while.