Multiplexer: all you need to know

chip multiplexor

A multiplexer is a combination circuit that has several inputs and a single data output. This allows you to select the step of only one of its inputs to channel it to its output. That is, you could select from which input to take the data or bit at the input and ignore the rest of the inputs. This is very common in electronics when several connections need to share a single line or bus.

That is, by controlling the multiplexer you can select the appropriate input at any time. This makes it possible to work with multiple input devices at the same time without them interfering with each other, even though there is only one connection. Also, you should know that usually a demultiplexer is used in conjunction with the multiplexer in many projects .

What is a multiplexer?

multiplexor

These combinatorial services called multiplexers are usually not complex. They are composed of a few logic gates depending on their amount of data and control inputs could increase the complexity. They usually include 2 inputs and a single output, as well as control lines. And several of them can be used in combination to increase that number of available inputs.

It can be understood as a selector. For example, imagine you have a very simple one with two inputs, the simplest one you can build. That circuit will have a single control input and output. If the inputs are A and B, with the control input you can control if it is A who passes his value to the output S or if it is B who does it. To do this, you only have to vary the value of the control line C. For example, if C=0 it will be A and if C=1 it will be B.

As you will understand, if there are more inputs you will need more control inputs for selection. In fact, the multiplexer is a special type of decoder, with an enable signal for each AND gate included and an OR gate between the output and the AND gates. That way it can be easily selected.

As for its applications, you can use it for a lot of things:

  • Input selector to share a single bus or line when you have multiple inputs.
  • Serializer to take the value of each of your entries in order.
  • For multiplexed transmission using the same connection lines for various device data. For example, imagine you want to use the same data pin of a microcontroller to connect several device outputs, but it can only send information one at a time .
  • Perform logical functions, etc.

Multiplexer types

Depending on the way the transmission is divided, there are several types of multiplexers or multiplexing:

  • By frequency division
  • By time division
  • By code division
  • By wavelength division

As you can imagine, they are controlled by frequency, by time through a clock, by binary code, and by wavelength. But here I’m only interested in the conventional…

In addition to the types, as with the demultiplexer, you can find it with more or less channels 2, 4, 8, 16, etc., depending on what you need for your DIY projects.

Differences with a demultiplexer

demultiplexor

In digital electronics there is the demultiplexer, a combinational circuit that is the antagonist of the multiplexer. In this case there will only be one input of information, but it can be transmitted through its various outputs. That is, in this case, the control signals will decide to which output the input data is transferred.

If you have a demultiplexer at the output of a multiplexer, you can have a very useful system for learning how both devices work.

Where to buy?

multiplexor demultiplexor

These devices are usually implemented on very simple DIP chips. You can find them in a variety of brands and with a number of inputs or outputs in case of a demultiplexer. In addition, they are easily found in various specialized media or online stores. If you are interested in buying one at a good price, these can be good examples to start with your projects:

I advise you to read the datasheets of their manufacturers to get a clear idea of their pinout, as they may vary depending on the manufacturer or type you have purchased.

cd74hc4067

In addition, as you can see, there are also very good modules that allow you to have both devices in one. This is the case of the known CD74HC4067, a small module with TTL technology that can help you to work with its 16 banals in a bidirectional way, having MUX/DEMUX. That is, you can use it as a kind of intelligent switch.

Thus, your Arduino can read and write on up to 16 different devices with only 5 pins, 4 of them used for control and an additional one to pick up the signal to be read or written according to the selected channel.

The good thing about this chip is that it works with both digital and analog signals, so it is compatible with many sensors that work in analog and other digital chips, as well as many different electronic elements. It gives great versatility. That is why they are also called I/O expanders or input/output amplifiers .

You could even use it for the serial port communications, the I2C bus, or the SPI, which we have already discussed on other occasions.

However, before working with it, you must make sure that you comply with the voltages and intensities that this circuit admits so as not to damage it. For example, in this case it can provide up to 20 mA, as well as a voltage of 2 to 6v. However, if you want to work with higher currents you could use a relay or a transistor.

Integration with Arduino

Arduino with Bluetooth

One way to have more inputs on your Arduino board or more outputs is to use these multiplexers and demultiplexers. With them you will avoid having to buy a higher priced board that has more pins, or having to use other tricks to be able to connect everything you need.

For example, you can use a ‘string’ module MUX and DEMUX to have both in one element, and then simply integrate it into your Arduino project. With the CD74HC4067 you can connect it very easily, so follow these rules:

  • Vcc of the MUX/DEMUX chip you must connect it to Arduino Vcc or 5V.
  • GND, the ground, must be connected to Arduino’s GND.
  • The pins marked S0, S1, S2, S3 control the active channel, with four Arduino digital I/O, such as D8, D9, D10 and D11.
  • The EN is also enabled, so that it works as a multiplexer you can connect it to Arduino’s GND.
  • And GIS is the output signal that will determine the selected channel. It can be connected to Arduino or any device that needs to read the output. In this case I have connected it to
  • A0 to get the values from Arduino itself.
  • At the other end of the module you will have the inputs in this case, which are C0-C10 that you can connect to your devices.Once connected, the Arduino code can be simple.
  • Arduino IDE’s sketch as multiplexer can be as follows (this code will only turn their channels off and on respectively, but you can modify it to make the project you want):

const int muxSIG = A0;
const int muxS0 = 8;
const int muxS1 = 9;
const int muxS2 = 10;
const int muxS3 = 11;
 
int SetMuxChannel(byte channel)
{
   digitalWrite(muxS0, bitRead(channel, 0));
   digitalWrite(muxS1, bitRead(channel, 1));
   digitalWrite(muxS2, bitRead(channel, 2));
   digitalWrite(muxS3, bitRead(channel, 3));
}
 
void setup()
{
   pinMode(muxSIG, OUTPUT);
   pinMode(muxS0, OUTPUT);
   pinMode(muxS1, OUTPUT);
   pinMode(muxS2, OUTPUT);
   pinMode(muxS3, OUTPUT);
}
 
void loop()
{
   for (byte i = 0; i < 16; i++)
   {
      SetMuxChannel(i);
      digitalWrite(muxSIG, HIGH);
      delay(200);
      digitalWrite(muxSIG, LOW);
      delay(200);
   }
}

If you want to use it as a DEMUX, you should only consider that C0-C10 would be the outputs and GIS would be the input. In case you want to use it as a demultiplexer, the code would change like this:


onst int muxSIG = A0;
const int muxS0 = 8;
const int muxS1 = 9;
const int muxS2 = 10;
const int muxS3 = 11;
 
int SetMuxChannel(byte channel)
{
   digitalWrite(muxS0, bitRead(channel, 0));
   digitalWrite(muxS1, bitRead(channel, 1));
   digitalWrite(muxS2, bitRead(channel, 2));
   digitalWrite(muxS3, bitRead(channel, 3));
}
 
void setup()
{
   Serial.begin(9600);
   pinMode(muxS0, OUTPUT);
   pinMode(muxS1, OUTPUT);
   pinMode(muxS2, OUTPUT);
   pinMode(muxS3, OUTPUT);
}
 
void loop()
{
   for (byte i = 0; i < 16; i++)
   {
      SetMuxChannel(i);
      byte muxValue = analogRead(muxSIG);
 
      Serial.print(muxValue);
      Serial.print("t");
   }
   Serial.println();
   delay(1000);
}

Remember that you can get more information with the help of our free Arduino programming course.

Leave a Comment

*

*