Electronic – How to interface LDR with microcontroller

adcinterfaceldrmicrocontrollersensor

I need to interface an LDR with a microcontroller.

While searching for some circuit ideas on the internet, I came across two different ideas:

  • One was using a voltage divider circuit with another resistor and input that into the ADC port of a microcontroller.

  • Another was to couple the LDR to ground via small capacitor and connect the other end directly to a microcontroller. (I am not sure how this works?)

    For example:

    schematic for measuring light using LDR without an ADC

    Image source: Measuring Light on a PIC 16F62x from Robot Builder

    The PIC 16F62X series is a pin-compatible upgrade to the old F84 offering lots of extra internal goodies such as timers, a USART and a couple of comparators. There are no analogue to digital converters (ADC) as such but it is a simple job to use a comparator, a timer and a few lines of software to make one.

Which one is more accurate?

Best Answer

This is very simple:

Since both the voltage into the A/D input and the A/D's measuring range is relative to the PWR voltage, the PWR voltage cancels out. The A/D pin voltage will be non-linear with light intensity. Make R2 the value R1 has in the center of its range or where you want the most resolution.