Image of LDR

I'm doing a project and my teacher told me that the GPIO pin cannot supports analog inputs like the LDR, so I went to try and it works perfectly without the Analog Digital Conversation IC. Why is that so?

  • 2
    so, you get a range of values from this device connected to an unspecified GPIO pin? or do you just get a binary bit of "data" - i.e. 1 or 0, HIGH or LOW, ON or OFF, whatever you call it – Jaromanda X May 31 '18 at 6:56
  • You have offered no evidence it works and the question will have no relevance to the Pi. – joan May 31 '18 at 7:07

Since the current Raspberry Pis have no analog inputs, I'm assuming that you are getting a 1 or 0, depending on the light level. This makes perfect sense.

An LDR (Light Dependent Resister), or photocell for old fogies such as myself, acts like a resister that changes value depending on the amount of light shining on it.

If you have a normal resister hooked up to 3.3v and ground (with another resister in series so that you don't waste too much power), sort of like:

3v3 -- resister -A- LDR -- ground

Put a GPIO pin at A. With the proper resister (experimentation will work to get the right value) you will have the pin reading a logic one or zero depending on the light recieved by the LDR.

You'll get more information with an ADC (Analog to Digital Converter), but sometimes you don't need to all that information. If you just need to know that if it is dark, than a simple logic circuit is cheaper and easier.


All GPIO pins on the RPi have Schmitt triggers, so they effectively work as 1-bit ADCs, converting the voltage level to a logical leve: below ~0.8V you read 0, above ~1.3V you read 1, and in between you read the old value that the pin had. This hysteresis can be turned off, at which point it is your task to make sure the pins are never floating between 0.8V and 1.3V, meaning you can only drive them with digital signals.

With resistive sensors (e.g. LDR), RPi can be used to implement a rudimentary ADC based on time measurement. Basically, you add a capacitor which forms an RC circuit and measure the time it takes to switch from 0 to 1. Since this time is proportional to R*C and C is constant, you can estimate R.

  • I remember doing this in the early days of personal computing (late 1970's). I remember it being fairly accurate. – NomadMaker Jun 1 '18 at 13:00
  • @NomadMaker it gets much less accurate on a system with unpredictable interrupts, like Linux. – Dmitry Grigoryev Jun 1 '18 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.