I'm in the planning stages for a project using the Arduino Uno to control 8 distance sensors, and have run into a little road block, the Uno only has six input pins. So I'm wondering, is there any way for this to work? If so, how?
There's more than one way to do it (TMTOWTDI).
There are a several ways to connect 8 analog inputs to an Arduino.
- Add an analog multiplexer, as georgebrindeiro suggested. Such as: (a), (b), (c), (d), etc.
- Replace the Arduino with one that has enough analog inputs already built-in. Such as the Arduino Mini with 8 analog inputs, the Arduino Due with 12 analog inputs (b), (a) the Arduino Mega with 16 analog inputs (b), the Teensy 3.0 with 14 analog inputs (c), etc.
- Add one or more external ADCs, and connect it to digital pins of your CPU. Such as: Arduino 4-20mA Shield with 16-bit ADC (a); ADS1115 16-Bit ADC -- with 4 of these boards, 2 digital pins from the Arduino are used to read 16 analog inputs (b); MCP3208 8 channel 12 bit SPI ADC (c); 8-channel 16-bit Raspi analog board (d); Arduino and the LTC2440 24bit ADC (e) (f); "The Brick" 8 Single Ended 16 Bit Analog Inputs (g); etc.
p.s.: Multiplexing analog inputs requires an "analog multiplexer" -- most multiplexers are "digital muxes" which won't work with analog inputs.
p.p.s.: All the ultrasonic distance sensors I've used only require digital I/O pins. What kind of distance sensors are you using?
Whenever you have more signals than appropriate inputs in a digital system, you likely need a multiplexer or simply mux. An M-to-N mux is a circuit that enables you to select which of M input signals you want to output to N mux outputs, usually using digital pins to make that selection.
Googling quickly, I found this solution for the Arduino Uno: a Mux Shield. Hope that helps!