How-To: Read Analog Sensors with the Raspberry Pi


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.

Comments are closed.

Discuss this article with the rest of the community on our Discord server!

Matt Richardson is a San Francisco-based creative technologist and Contributing Editor at MAKE. He’s the co-author of Getting Started with Raspberry Pi and the author of Getting Started with BeagleBone.

View more articles by Matt Richardson

ADVERTISEMENT

Maker Faire Bay Area 2023 - Mare Island, CA

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 15th iteration!

Buy Tickets today! SAVE 15% and lock-in your preferred date(s).

FEEDBACK