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.

BY Matt Richardson

Matt Richardson is a Brooklyn-based creative technologist, contributing editor for MAKE magazine, and co-author of Getting Started with Raspberry Pi. He's also the owner of Awesome Button Studios, a technology consultancy. Highlights from his work include the Descriptive Camera (a camera which outputs a text description instead of a photo) and The Enough Already (a DIY celebrity-silencing device). Matt's work has been featured at The Nevada Museum of Art, The Rome International Photography Festival, Milan Design Week and has garnered attention from The New York Times, Wired, and New York Magazine.

One Response to How-To: Read Analog Sensors with the Raspberry Pi

  1. Bosstiger on said:

    Reblogged this on Gigable – Tech Blog.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

%d bloggers like this: