Use digital I/O pins to measure analog voltage

Building a cool microcontroller-based project, and wish you had just one or two more analog inputs? Or perhaps you are trying to make something using the tiniest microcontroller possible, and don’t have any analog ports in the first place? Well, it turns out that you can use a couple of digital I/O pins and a single capacitor to build a crude analog to digital converters (ADC). Let’s Make Robots user Telefox has a nice overview about building a Low-cost ADC using only Digital I/O. The technique isn’t new, but it is a cool idea, and building your own would be a great way to learn how ADCs work.

If you are itching to squeeze as much performance out of your tinly microcontroller as possible, I second his recommendation of Microchip’s Tips ‘n Tricks manual. It’s a neat guide that I read when I was getting started with microcontrollers, and learned all sorts of cool tips from- including the technique that is now referred to as Charlieplexing.

4 thoughts on “Use digital I/O pins to measure analog voltage

  1. Nice and simple idea, but I have one quibble with the posting: This technique as presented is to measure analog resistance, not voltage.

    You can use a *single* I/O pin, with one resistor and cap to measure voltage, but you have to take two timer measurements, and if the voltage is varying over the short time, you wont get accurate results.

    Use the same concept with only Digital I/O Pin 1, and cap to ground. Apply the unknown voltage to the pin/cap junction through a know resistor. Set the pin as Output, and High, reset to Input, and time until you get a zero. If you don’t get zero within (R*C seconds), set it as Output and Low. Reset to Input, and time until you get a one.

Comments are closed.