# Issues With Multiplexing 16 to 1

**URL:** <https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231>\
**Category:** LEDs and Multiplexing\
**Created:** [August 15, 2022, 12:30am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231 "2022-08-15T00:30:33Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmayeads](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@dmayeads](https://forum.arduino.cc/u/dmayeads)\
**Post date:** [August 15, 2022, 12:30am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/1 "2022-08-15T00:30:33Z")

</div>

Sorry if I posted in the wrong place. I picked this category because it had multiplexing in the name.

I'm working on a project where I hope to use an Uno R3 to make resistance measurements for a cable assembly. Of course, this will be a calculated resistance via a voltage divider. Unfortunately, I can't seem to get the MUX board to work reliably.

I'm using a 16-channel analog multiplexer breakout package based on the 74HC4067. The data reported has little if anything to do with the input value. I can set it for 5V or ground and get the same crazy outputs.

Here is the setup. It's everywhere so I copied it from somewhere:  
 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/2/e/3/2e38626574e93d911e4199fb4142350e43a9f644.png)

Here is the code I'm using. I've tried so many different variations on the same code I can't remember how many examples I've tried:  
`

```cpp
// 74HC4067 multiplexer (16 to 1)

// control pins output table in array form
// see truth table on page 2 of TI 74HC4067 data sheet
// connect 74HC4067 S0~S3 to Arduino D7~D4 respectively
// connect 74HC4067 pin 1 to Arduino A0   
byte controlPins[] = {B00000000, 
                  B10000000,
                  B01000000,
                  B11000000,
                  B00100000,
                  B10100000,
                  B01100000,
                  B11100000,
                  B00010000,
                  B10010000,
                  B01010000,
                  B11010000,
                  B00110000,
                  B10110000,
                  B01110000,
                  B11110000 }; 

// holds incoming values from 74HC4067                  
byte muxValues[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};

void setup()
{
  Serial.begin(9600);
  DDRD = B11111111; // set PORTD (digital 7~0) to outputs
}

void setPin(int outputPin)
// function to select pin on 74HC4067
{
  PORTD = controlPins[outputPin];
}

void displayData()
// dumps captured data from array to serial monitor
{
  Serial.println();
  Serial.println("Values from multiplexer:");
  Serial.println("========================");
  for (int i = 0; i < 16; i++)
  
  {
    Serial.print("input I"); 
    Serial.print(i); 
    Serial.print(" = "); 
    Serial.println(muxValues[i]);
    delay(50);
  }
  Serial.println("========================");  
} 

void loop()
{
  for (int i = 0; i < 16; i++)
  {
    setPin(i); // choose an input pin on the 74HC4067
    delay (500);
   muxValues[i]=analogRead(0); // read the vlaue on that pin and store in array
   // int val = analogRead(0);

   //muxValues[i]=(val * 5.0) / 1024.0;
   //muxValues[i] = val; 
  }

  // display captured data
  displayData();
  delay(2000); 
}

```

I've tried different modules, two different Uno boards, and wired and rewired everything multiple times.

Here is what I know:

- The program is setting the binary address properly. I verified it with LEDs.
- Placing 5 VDC or 3.3 VDC on the channel doesn't change anything. I've even tied all unused channels to ground with the same results.
- I'm getting similar results with all modules I try
- I get the same results if I set the binary address manually
- I've tried various pull-up resistors and even voltage dividers to see if it's an issue.

Here is an example of the output data I'm seeing:  
 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/2/b/1/2b15c2cd9da02af57a09cbf5b69269d965067f12.png)

It's never the same data twice. The boxed channel has a 5V input.

Usually, when this happens to me I smack my head because I missed something very obvious. I have asprin on stand-by for when someone tells me of an obvious solution.

Thanks!

Dave.

---

<div class="post-metadata">

**Author:** ![cncnotes](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cncnotes/32/1098836_2.png) [@cncnotes](https://forum.arduino.cc/u/cncnotes)\
**Post date:** [August 15, 2022, 12:37am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/2 "2022-08-15T00:37:26Z")

</div>

Could you please post a schematic of exactly how you have connected the pins. The above picture is hard to interpret.  
And a link to the module you are using.

And please post your code in code-tags per forum guidelines. You can update your current post. Code tags is the button that looks like \</\>

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [August 15, 2022, 12:51am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/3 "2022-08-15T00:51:45Z")

</div>

**[Read the forum guidelines](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966#posting-code-and-common-code-problems)** to see how to properly post code and some good information on making a good post.  
Use the [IDE autoformat tool](https://www.tutorialspoint.com/auto-format-code-in-arduino-ide) (ctrl-t or Tools, Auto format) before posting code in code tags.

You can go back and **fix your original post** by highlighting the code and clicking the \</\> in the menu bar.  
 ![code tags new](https://europe1.discourse-cdn.com/arduino/original/4X/4/7/0/47090818c9d4d7d934b4b44ab7b96e834ea3164c.jpeg)

> [@dmayeads](#):
>
> PORTD = controlPins[outputPin];

It looks like you are writing to port D (pins 0-7) but connected to pins on port B (pins 8-13).

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/e/8/4/e84c4877c8bc91e41964816340ab278259da2dc2.jpeg)

See this page: [Arduino Project Hub](https://create.arduino.cc/projecthub/Hack-star-Arduino/learn-arduino-port-manipulation-2022-wokwi-systems-simulat-10f9af)

---

<div class="post-metadata">

**Author:** ![dmayeads](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@dmayeads](https://forum.arduino.cc/u/dmayeads)\
**Post date:** [August 15, 2022, 1:44am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/4 "2022-08-15T01:44:26Z")

</div>

Thanks for the response. Sorry for the posting errors....I'm new to the forum.

Here is the link for the module (or one of the several just like it):

> **[Interfacing CD74HC4067 16-Channel Multiplexer with Arduino- Electropeak](https://electropeak.com/learn/interfacing-cd74hc4067-16-channel-analog-digital-multiplexer-with-arduino/)**
>
> Learn How to interface a CD74HC4067 16-Channel Multiplexer with Arduino. using CD74HC4067 Multiplexer example code, circuit, pinout, library

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/6/6/3/663e440584b1a64e4e1b808365cbcda3cc93f13e.jpeg)

I should have drawn this out to begin with. I've tried so many ways, I got confused.......

---

<div class="post-metadata">

**Author:** ![camsysca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/camsysca/32/1015228_2.png) [@camsysca](https://forum.arduino.cc/u/camsysca)\
**Post date:** [August 15, 2022, 1:46am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/5 "2022-08-15T01:46:07Z")

</div>

Very hard to read the module labelling. Link to product, please. Looks like there might be a pin labelled "EN" - if so, that's likely an enable. If not set to the correct voltage level, your input will be floating.  
C

---

<div class="post-metadata">

**Author:** ![camsysca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/camsysca/32/1015228_2.png) [@camsysca](https://forum.arduino.cc/u/camsysca)\
**Post date:** [August 15, 2022, 1:47am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/6 "2022-08-15T01:47:53Z")

</div>

I see you've posted more info, and a new diagram. Addresses my comment.

---

<div class="post-metadata">

**Author:** ![camsysca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/camsysca/32/1015228_2.png) [@camsysca](https://forum.arduino.cc/u/camsysca)\
**Post date:** [August 15, 2022, 1:50am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/7 "2022-08-15T01:50:35Z")

</div>

Did you try it with EN high, as well as low? Wouldn't be the first time a description was flat out wrong.  
C

---

<div class="post-metadata">

**Author:** ![dmayeads](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@dmayeads](https://forum.arduino.cc/u/dmayeads)\
**Post date:** [August 15, 2022, 2:17am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/8 "2022-08-15T02:17:32Z")

</div>

Yes. I tried enable as high, low and controlled by another digital line.

---

<div class="post-metadata">

**Author:** ![dlloyd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dlloyd/32/751911_2.png) [@dlloyd](https://forum.arduino.cc/u/dlloyd)\
**Post date:** [August 15, 2022, 2:24am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/9 "2022-08-15T02:24:06Z")

</div>

This disables serial on pins 0 and 1:

```cpp
DDRD = B11111111; // set PORTD (digital 7~0) to outputs

```

This only sets D7~D4 as outputs and leaves pins D3~D0 as is (no change):

```cpp
DDRD |= B11110000; // set PORTD (digital 7~4) to outputs

```

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [August 15, 2022, 2:30am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/10 "2022-08-15T02:30:36Z")

</div>

Hi,  
Welcome to the forum.  
Is there a reason you are using direct port comms?

Have you tried the library to do all your port commands?

> **[CD74HC4067 - Arduino Reference](https://www.arduino.cc/reference/en/libraries/cd74hc4067/)**
>
> The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.

Thanks.. Tom.. 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![dmayeads](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@dmayeads](https://forum.arduino.cc/u/dmayeads)\
**Post date:** [August 15, 2022, 2:46am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/11 "2022-08-15T02:46:41Z")

</div>

I downloaded a different library, but I wasn't impressed. Besides, I understand ( **or at least I thought I did** ) the raw commands. I'm going to download this library and try again.....

Dave.

---

<div class="post-metadata">

**Author:** ![dmayeads](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@dmayeads](https://forum.arduino.cc/u/dmayeads)\
**Post date:** [August 17, 2022, 2:25am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/12 "2022-08-17T02:25:58Z")

</div>

All,

First, thanks for the responses. It's funny, I design and build automated test systems for a living and I'm having more trouble with this than I do with an automated system with several pieces of test equipment, relays, and yes, MUX cards.

I tried running the module(s) manually. I'm still getting garbage out in either direction. I've decided there has to be something wrong with the modules. I didn't pay much for them and you get what you pay for.

I ordered more modules from a different vendor. I also ordered brand new 4067 DIP package chips. I'll try those as well.

Thanks again and I'll post how things go.

Dave

---

<div class="post-metadata">

**Author:** ![dmayeads](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@dmayeads](https://forum.arduino.cc/u/dmayeads)\
**Post date:** [August 17, 2022, 2:28am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/13 "2022-08-17T02:28:03Z")

</div>

Thanks. I did this in an attempt to get the darn things to work. It didn't help to set these back to the original settings.

---

<div class="post-metadata">

**Author:** ![Wawa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wawa/32/1211303_2.png) [@Wawa](https://forum.arduino.cc/u/Wawa)\
**Post date:** [August 17, 2022, 2:43am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/14 "2022-08-17T02:43:41Z")

</div>

> [@dmayeads](#):
>
> I'm working on a project where I hope to use an Uno R3 to make resistance measurements for a cable assembly. Of course, this will be a calculated resistance via a voltage divider...

Red lights are blinking here.

Remember that all pins of a muxer must be within the muxer's supply/ground voltage limits.  
Leo..

---

<div class="post-metadata">

**Author:** ![dmayeads](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@dmayeads](https://forum.arduino.cc/u/dmayeads)\
**Post date:** [August 17, 2022, 3:04am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/15 "2022-08-17T03:04:30Z")

</div>

Thanks. Even when I set this up manually, the darn thing isn't working. I'm powering the module with 5V from the Uno. I'm using it for the ground too. I've tried 3.3 Volts as a binary set as well as 5V.

I even set an r-s latch to control the digital lines, S0-S3. I used a voltage divider to set the binary inputs to various levels from 3.3V, 4V, and 5V.

I'm out of ideas until the new modules arrive. I can't believe I have 5 bad modules, but I can't think of anything else that causes the chips to be utterly uncontrollable.

Thanks!

Dave

---

<div class="post-metadata">

**Author:** ![dlloyd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dlloyd/32/751911_2.png) [@dlloyd](https://forum.arduino.cc/u/dlloyd)\
**Post date:** [August 17, 2022, 3:07am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/16 "2022-08-17T03:07:19Z")

</div>

> [@dmayeads](#):
>
> It didn't help to set these back to the original settings.

```arduino
DDRD &= ~B11110000; // set PORTD (digital 7~4) to inputs, leave 3~0 unchanged

```

---

<div class="post-metadata">

**Author:** ![JBBOP](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jbbop/32/1098850_2.png) [@JBBOP](https://forum.arduino.cc/u/JBBOP)\
**Post date:** [August 17, 2022, 4:15am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/17 "2022-08-17T04:15:48Z")

</div>

Seems you have an electronics design problem. Post an schematic of your measuring circuit, along with resistance values of your cable assemblies to better help.

---

<div class="post-metadata">

**Author:** ![dmayeads](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@dmayeads](https://forum.arduino.cc/u/dmayeads)\
**Post date:** [August 17, 2022, 5:08am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/18 "2022-08-17T05:08:58Z")

</div>

All,

It was the cheapo module causing the problem. The package on the bad one looks significantly different than the one that's working.

Thanks again for all of the assistance.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 13, 2023, 5:09am UTC](https://forum.arduino.cc/t/issues-with-multiplexing-16-to-1/1022231/19 "2023-02-13T05:09:23Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
