Discussion in 'General Electronics Chat' started by FroceMaster, Feb 21, 2015.

  1. FroceMaster

    Thread Starter Active Member

    Jan 28, 2012
    how can i get a LDR connected to an input on 16F1509. So that when the volt drops or pastca value the MCU do something.
    can i just connect from 5v thrue the LDR and another Resistor to ground and the the MCU can mesure the voltage ??
  2. MrChips


    Oct 2, 2009
    You do not necessarily have to measure the voltage. The result from a digital input pin will either be zero or one depending on the light intensity falling on the LDR.
  3. Reloadron

    Well-Known Member

    Jan 15, 2015
    You can pick your poison:


    The Vout will be a function of the LDR and Resistor forming a divider. If you run that Vout into an analog channel then you write the code to do whatever you want the program do do if Vin is above or below the level you choose. Depending on the LDR the Vout in the attached drawings will either increase or decrease with light or darkness on the LDR.

    FroceMaster likes this.
  4. ian field

    AAC Fanatic!

    Oct 27, 2012
    LDRs are getting harder to find because they aren't RoHS compliant with cadmium-sulphide as the main material. They also have a pretty slow response time.

    eBay still had them listed last time I looked (plenty from China) but its getting harder to find any main component suppliers that still carry them.

    You can do the same job with a photo-diode, even though they're better suited to IR - but the photocurrent is much lower than an LDR.

    Its sort of traditional to use a Schmitt-trigger in light sensing circuits, so you could conveniently use a LM358 op-amp with one stage as high input impedance voltage follower, and the second stage as the Schmitt.