One of the drawbacks to the Raspberry Pi is that there’s no built-in analog-to-digital converter, meaning that it can’t read analog sensors “out of the box.” Luckily, our friends at Adafruit recently posted a tutorial on how to hook up an external ADC chip (the MCP3008 to be precise) to the $35 embedded Linux platform. But what if you want to read the values from a resistive sensor, like a photocell, and don’t have an external ADC chip handy? Adafruit shows us how to watch the timing from a capacitor to get a reading from those sensors:
The way we do this is by taking advantage of a basic electronic property of resistors and capacitors. It turns out that if you take a capacitor that is initially storing no voltage, and then connect it to power (like 3.3V) through a resistor, it will charge up to the power voltage slowly. The bigger the resistor, the slower it is.
Keep in mind that this method isn’t a panacea for analog sensor reading on the Raspberry Pi. For one, only resistive sensors like photocells, flex sensors, and force-sensitive resistors will work this way. Also, the readings can be “a little flakey” because the method depends on timing, and that can vary based on how busy the Pi’s processor is with other tasks. Check out their full writeup for the details and all their Raspberry Pi tutorials on the Adafruit Learning System.