Multiplexing Analog sensors via I2C or SPI

It might look a noob question and it probably is.

I saw in, that it's possible to mux multiple analog sensor output to digital in an "easy" way.

Using the CD74HC4067 enables (not sure) me to create lots of 16 sensor modules. But can I connect multiple muxes like SparkFun Analog/Digital MUX Breakout - CD74HC4067 - BOB-09056 - SparkFun Electronics and send the results via I2C or SPI? That would avoid me connecting every mux to it's own Arduino.

I need to connect dozens of sensors based on QRD1114 to a central location. Don't need a super fast system. Every sensor must be read once every second.

So I imagine I would need to connect every mux to a i2C or SPI board and then each slave to a master Arduino.

Is this possible and the best approach?

Read the tutorial at link at the bottom of the Sparkfun page for more applicaton info. It should be pretty straightforward.

How about feeding each 4067 output into 1 of the 8 inputs on a MCP3208,
and let an arduino select which output (4 pins to 4067) goes into the MCP3208 and which channel is then selected (SPI command, 4 pins). Leaves 12 pins free - keep 2 for serial, still have 10 pins free.
Can have several MCP3208 connected, just need an additional chip select for each one.
16 4067 into 8 channels = 128 inputs, 10 2/3 dozen.
Need more? Add a 2nd MCP3208 for another 128.
MCP3208 needs far fewer clocks (I think 12uS total) to obtain a signal than internal ADC (110uS).

If slower ADC is acceptable, than a Promini (or board with a surface mount '328 chip) with A6/A7 broken out can also handle the outputs from 8 4067's.

Hi Crossroads,

Thanks for the reply, but not being good in electronics, I’m perhaps missing something or not being clear myself.

I’ve attached a high level sketch of what I’m planning.

I have one “module”, let’s name it A. It has 12 QDR1114 IR photo sensors. In order to make the solution work, I need somethign between 6 to 30 modules.

So that’s the idea of make “stand-alone” modules, each one in a certain way independent from the other. This makes setup easy, as you only need to add more modules to teh system and in case of failure, it’s easy to diagnose and replace.

The idea of using the Pro Mini 328 (5v) is also interesting, but I would need to put 2 per “module”, as I need 12 sensors. And then connect everything via I2C. Depending on costs it seems interesting, as I might have more inteligence at each module.

Let me know your thoughts.

If using the Pro mini, I imagine I will need something like this to connect the I2C bus to a RaspPI.

Also wondering if I can use something like this: Mixed-signal and digital signal processing ICs | Analog Devices.

If you use a Pro-Mini you will need an FTDI BASIC to upload code . (sparkfun)
Why not use this ?
ADS1115 16-Bit ADC - 4 Channel with Programmable Gain Amplifier : ID 1085 : $14.95 : Adafruit Industries, Unique & fun DIY electronics and kits (I2C 16-bit ADC)

If you get one remember to change one line.
It comes with the example like this:

// Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */
Adafruit_ADS1015 ads;     /* Use thi for the 12-bit version */

Note that the default config is the 12-bit version. If you get the 16 bit version you have to change it to this:

 Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */
//Adafruit_ADS1015 ads;     /* Use thi for the 12-bit version */

to configure it for 16-bit.

Hi Ras,

Thanks for that. I checked that one, but since I need to get 12 analog sensors per "module" (as on the image), I would need 3x ADS1115 for the task, making the solution more expensive.

I may be wrong, but I think that using this solution I can only have a limted number of elements on the I2C bus.

If you use the 4 -channel ADS1115
and the 16 channel multiplexer,

and read four sensors with each ADC channel (sensors 1-4 => inputs 1-4 => ADC CH-1
(sensors 5-8 => inputs 5-8 => ADC CH-2
(sensors 9-12 => inputs 9-12 => ADC CH-3
(sensors 13-16 => inputs 13-16 => ADC CH-4

At first glance this doesn’t seem any better than multiplexing all 16 channels to one ADC channel.
The values would need to stored in an array and then displayed after “n” samples are averaged.

I made the simple sketch attached to see if I’m going on the right track.

This is the mini I’ll be using:


I was doing some tests with one QRD1114, but something might not be right on the emiter.

Testing it with the curtains open, you can see the values changing as I move from light to shadow. But if I close the windows to avoid any IR radiation from the sun, I get no response from the receiver. Even if I disassemble it and put one in front of the other I just get 0 as response.

In the mean time, I was checking a solution with push buttons and might me a solution as well, and it's working. The components are also cheaper.

I'll give it another try on the QRD1114. I ordered a few more components, as I might have got a bad one.