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?
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It only takes a minute to sign up.Sign up to join this community
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.