How to read several infrared sensors using one MCU pin


Oscar has written an article describing a technique he’s used for reading multiple analog sensors with one MCU ADC pin. He was designing a line-following robot and wanted to read several infrared sensors without having to dedicate an analog read pin for each. His solution uses “a Schmitt trigger inverter whose output has resistors connected in a series of different values attached to a common point. From this point the voltage value is measured, which will be different depending on the active sensor, being able to know the position of the robot.”

You can find the complete explanation of Oscar’s project on his website. Note that this is a multi-lingual post.

Via the contact form.

This entry was posted in how-to, Interface, robotics, sensors, techniques and tagged , .

Comments

  1. rsdio says:

    With binary weighting, this could almost correlate each input pin with a bit in the A/D result, although it would probably require 10-bit A/D and some smart quantization.

  2. mike says:

    if all you want is a binary value then why not attach these 8 sensors to a 74HC165N or similar and then read the incoming byte? 00010000 will mean sensor 4 crossed the line.

    • rsdio says:

      A/D needs only 1 pin, the 74HC165N needs at least 2 for clock and data. In that respect, this idea can prove useful.

      However, if you read the entire web site he suggests using the ADC0831 and in that case you’re absolutely right, Mike. There’s no point in using this hack when you’re adding an external chip that requires a couple of pins to interface. It makes way more sense to add a parallel input shift register instead of dealing with fuzzy resistor values.

  3. Colin says:

    From his website, roughly translated:

    Having to use I2C (2 pin) or SPI (4 pin) and we are losing the advantage of handling a single pin, in addition to communications that these buses have to send and receive commands and data, so you get the status of sensors is not so straightforward. However, the I2C is a good option for when you have an analog pin as it would be fast enough to not take a PID control and would use only 2 pins.

  4. mike says:

    That’s true.

    I guess I’ve been looking at i2c chip data sheets so much lately, I can’t imagine anything without that bus in use.

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.