# Use LDR with 220 ohm resistor

I have read many tutorials on LDR(Light dependent resistor) with Arduino which includes a 10 kilo ohm resistor but can i use it with 220 ohm resistor or even without resistor.

• Do the math. If you know what you're doing, sure. However, the fact that you're asking suggests that you're not quite sure what you're doing, so if you try, you'll likely have problems making it work, or even damage your micro. Jun 27, 2016 at 10:19
• You can use it with no external resistor: connect it between an analog input and GDN, then activate the internal pullup resistor. This pullup has a value somewhere between 10 and 50 kΩ, typically around 30 kΩ. The large uncertainty in the pullup value means you will not be able to compute the resistance of the LDR but, given some calibration, it should be OK for telling light and shadows apart. Jun 27, 2016 at 10:24
• can you post an answer with example
– Yash
Jun 27, 2016 at 10:28
• It can't hurt to use the 220Ohm. Though with most typical LDRs you won't get the range of different values. I.e. the values get from analogRead in the light, and in the dark will be closer to each other. Giving you a worst "resolution". Jun 27, 2016 at 13:56

Unless properly filtered, an LDR has a spectral sensitivity very different from the human eye, which makes it unsuitable for any kind of photometric measurement. It is also typically very loosely specified, so you won't know the illuminance it receives better than a factor two even if you measure its resistance very accurately. Thus, if you really need accurate illuminance measurements like, e.g., for complying with legal requirements, then forget the LDR and get a real luxmeter with a calibration traceable to the SI lux standard.

Now, if you only want to tell apart substantially different illuminance levels, like sunny and cloudy, then the LDR is fine. And don't let Majenko scare you into believing you really need to know the resistance of your pullup: it doesn't really matter.

That being said, you will get the best sensitivity if your pullup has a resistance in the same range as the resistance of the LDR in the typical conditions you will use it. Thus, if your LDR is nominally 10 kΩ, I would avoid pulling up with 220 Ω, as the sensitivity would be very poor. A 10 kΩ pullup resistor would be ideal, but the internal pullup of the I/O pin (20 – 50 kΩ, 30 kΩ typical) should be fine.

Many tutorials on LDRs use the ADC reading to compute a resistance, for which you need to know the resistance of the pullup. If you want to follow this path, just assume a 30 kΩ pullup. All your numbers will be somewhat off, but that makes absolutely no difference, because you don't know how to relate the resistance to the illuminance anyway.

I would suggest you forget about computing the resistance. Just look at the raw ADC readings instead. Take some test readings in the typical conditions that are of interest to you: now you have a baseline to which you can compare further readings against. Keep in mind, though, that the ADC readings get lower as the illuminance gets higher. And beware that the resistance of the pullup, and probably that of the LDR also, can be sensitive to temperature variations. You may do a hairdryer test to check whether it gets really bad.

Example code? This one is pretty trivial:

``````/* Connect an LDR between A0 and GND. */

void setup() {
pinMode(A0, INPUT_PULLUP);  // enable pullup for the LDR
Serial.begin(9600);
}

void loop() {
delay(1000);                     // delay for one second
}
``````
• Thank you The code worked with LDR. But as you said that it does not fit the legal requirements what specefic luxmeter shall i buy
– Yash
Jun 27, 2016 at 16:02
• Would BH1759 be fine?
– Yash
Jun 27, 2016 at 16:05
• @Yash: That's another question, and one I do not have the answer to. Jun 27, 2016 at 17:15

The simple fact is: you need a resistor with it. There's no getting away from that fact (short of building and using a constant-current source, but that's beyond the scope of this answer).

What value should the resistor be? Well, that depends on how sensitive or insensitive you want the LDR to be.

Yes, it will work with 220Ω, but will it give suitable results? Probably not. Ideally you want the resistor to be somewhere in the vicinity of the nominal resistance of the LDR - and that usually means 10s of KΩ.

As Edgar has mentioned, you can, at a pinch, use the internal pullup resistor of an IO pin instead of an external one (`pinMode(A0, INPUT_PULLUP)`), but the variability in the possible resistances that it might be make it pretty useless for anything more than "is it light or dark".

So you are best off getting a 10KΩ resistor where you then know that it is 10KΩ (or within a small percentage) and can calculate the LDR's resistance properly.

• The variability in the possible resistances may not be an issue if he is only building one single setup. Jun 27, 2016 at 10:45
• @EdgarBonet Yes, but without knowing what the pullup resistor value is, even on just a single setup, the returned ADC values are pretty meaningless, other than "light" and "dark". Yes, you could experimentally work out the resistance of the pullup if you really wanted, but the simple fact that the OP has had to ask this question means that such experimentation will be beyond him. Jun 27, 2016 at 10:46
• Typical LDRs are so loosely specified that, even with a 10.000 kΩ pullup, the ADC values are meaningless without prior experimentation. Jun 27, 2016 at 10:52
• @EdgarBonet At least with a known pullup you only have one unknown. That then allows you to calculate the actual LDR resistance. With two unknowns you have no hope at all. Jun 27, 2016 at 10:54
• @EdgarBonet Anyway, they're illegal in most civilised countries due to the use of cadmium. Jun 27, 2016 at 10:56