Improving LDR Resolution (Was: Emitter follower with PNP transistor)

I'm thinking about using an emitter follower to improve the resolution of a LDR in dark conditions (where the LDR gets to ~2 MOhm). I see on Wikipedia that I can make it with both NPN and PNP transistors, but I would use the latter since I have plenty, while I only have a few NPNs. Is there any counterindication to that? I see that PNP transistors are not recommended in certain situations, so I thought I would just ask.

Also, I don't need any resistors on the base and collector, right? On the emitter I would use a 4.7 kOhm, is that fine?

No transistor needed.
Arduino's input impedance is very high.
Higher than that transisor.
So you can make your LDR/resistor divider any value you like.
2.2 Megohm might even detect moonlight.
Leo..

For accurate readings, the resistance (impedance) seen by the analog input should not exceed 10K ohms.

You can use a high value resistor and an LDR in the dark, but you need a capacitor (say 10 nF) from the analog input to ground, to store charge for the sampling capacitor. You must also sample very infrequently, in order to allow the 10 nF capacitor to charge.

I can actually detect moonlight, but at the moment I do not seem to able to distinguish between "slightly dark" and "dark". I do not need accuracy when it's "not dark", but I would like to be able to distinguish among "varying degrees of darkness", as I am using that information to switch on a lamp, which must not happen too soon nor too late of course. Sorry for the non-really-scientific language but I hope you get the point :).

@jremington: I'm actually sampling across the other resistor in the voltage divider, not across the LDR, so I should be OK with the resistance, right? Also, please quantify "infrequently": I'm sampling once every 6 seconds at the moment. I would be happy to use a capacitor, but the transistor solution is just as good for me if that can work any better.

I don't know what the transistor does, as you didn't post the entire circuit. But, you certainly don't need it.

In my circuit, the sampling period should be longer than RC, where R is the resistive divider impedance (the parallel combination of Rload and Rldr) and C is the added capacitor from the input to ground.

1+ megohm is really high impedance to be measuring with the Arduino ADC directly

I'd put a rail-to-rail OPAMP in voltage follower configuration (tie out to the -/inverting input and the arduino analog pin, connect +/non-inverting input to the middle of resistor divider, and vcc and ground to... vcc and ground) - they're cheap and plentiful. Something like the MCP6002? 40 cents a pop from digikey in quantity 1, and available on ebay in the same general price range. It comes in both a DIP version and an SOIC version.

Also, unlike the trick with the capacitor, this will respond very rapidly to changes.

RC = 0.01 seconds for 1 Megohm and 10 nF, so you can sample at least 50 times per second.
Seems OK for moonlight.

Here are the parts I have on stock:

  • Electrolytic caps: 10 uF, 220 uF
  • Film caps: .0022 uF
  • Ceramic caps: 100 pF, 22 pF
  • OpAmp: F4558

Will any of these be fine? I don't need to sample often, even once a minute would be fine. I don't even need to react quickly to changes. Actually slower is even better ;).

What is your proposed circuit?

One of those you proposed! :smiley:

That opamp is no good, it's not rail to rail and it requires a dual supply, they show +5v and -5v as minimum supply.

I have a 100k resistor in series with a small LDR in a dark sensor for a night light.

I have it set to switch the light on at digital ~950 and off at digital ~925 if I remember.

Works fine.
Leo..

If you don't need a fast response, then you don't need to worry about it so much, just put a small cap from the middle of the divider to ground - though if you're only analog reading that one pin, you may not even need to do that.

Here is the circuit I would use, based on your 0.0022 uF cap.

LDR.gif

2.2nF is too small for accurate readings (to the LSB), 15nF is about the limit for that as
the sample/hold capacitor is 14pF according to the datasheet and you want to dominate
that by a factor of about 2^10 for a 10 bit ADC to avoid cross-talk between channels.

For this application 2.2nF will probably be fine as accuracy is not crucial.

The ADC input equivalent circuit is given in the datasheet.

Thanks for all your contributions guys, but maybe it's better to explain my issue properly.

I started with a simple voltage divider, LDR to +5V, 10kOhm to GND and A0 connected inbetween. This actually works pretty fine, I get "stable" readings with enough accuracy for my purpose.

My purpose is to control some lights, turning them on when it's "dark enough" and back off when day's dawning. In Italian this is called a "twilight switch", nice name :).

This means that I don't need to distinguish between "bright daylight" and "almost dark", those could both read full scale for me. But I need to distinguish between "slightly dark", "dark", "very dark", "darker", "darkest", etc. Currently I am not able to do this as my 0-1023 readings are more or less distributed like this:

  • ~150-1023: Daylight
  • 0-149: Dark
    I need far more accuracy in the darkness, sort of the opposite situation to this, with 100-150 steps for daylight and the rest allowing me to differentiate among varying degrees of darkness. This is why I was trying to "amplify" the current with the transistor. I hoped that with the lesser impedance at the transistor output readings would be better distributed. I also tried with different resistors but things don't change much.

The capacitor maybe smoothens the readings, but since I am averaging them in software (I take 10 readings a minute and average them) I might not need that.

Any suggestions?

Averaging systematically incorrect data results in systematically incorrect averages.

What are you referring to, in particular? I have now changed the resistor to 1 MOhm and added the 2.2 nF cap. I still have the LDR and resistor swapped since that would need to adapt the software, which I cannot do at the moment.

It's still pretty bright now and it's reading fullscale. Let's see how it behaves when it gets dark, although I'm pretty sure I'd already tried with such a big resistor.

You can calculate things with the data you already have.

When you get 0-150 digital with a 10k resistor, then the LDR must have been 60Kohm when "slightly dark".

That will give you 0-950 with a 1meg resistor.
Leo..

The photocell as part of a Wheatstone bridge and using a lower analog reference.