Use multiplexer with Arduino

By Emir

After while you will need more pins on Arduino to connect all devices you want.

Expand your Arduino pins with multiplexer is on of the cheapest and powerful solution.

Step 1

Introduction

Multiplexer is a device that selects one of several analog/digital signals and forwards the selected input into a single line. It can be use in both directions, to receive signal from sensors or to send signal (power supply usually) to sensor.

There are more types of multiplexers, operate with different numbers of channels and input/output pins.

In this tutorial we will use 8 channels multiplexer CD4051BE.

Step 2

Pins explanation

Multiplexer has several groups of pins. Numeration of pins starts from upper left corner and follow counterclockwise direction until right upper corner. Package marc (usually hole or half hole) have to be turned up, with opposite direction of pins from your point of view.

Channel pins are used to control external devices (input or output) using multiplexer. This model contains 8 pins (numbered from 0 to 7). They are not in row. First channel is on pin 13 (channel 0), second on pin 14 (channel 1), third on pin 15 (channel 2), fourth on pin 12 (channel 3), fifth on pin 1 (channel 4), sixth on pin 5 (channel 5), seventh on pin 2 (channel 6) and eighth on pin 4 (channel 7).

Address pins or selector pins A, B, C are pins 11, 10 and 9. This pins we will control from Arduino, and using only four pins (three for address and one for input/output) extend it to eight input/output pins.

Pin 3 is communication pin, means that selected channel will be connected with this pin, and using Arduino we will connect input or output pin on it to read or write on sensors using multiplexer.

Other pins are power supply pins.

Step 3

Use CD4051BE as multiplexer with Arduino

When we use it as multiplexer that mean select one of several input signals (analog or digital) and forwards the selected input into a single line.

Example on picture shows eight potentiometers connected on eight channels.

Connect multiplexer and devices pins as follow (see picture):

Pin 1 - Potentiometer's middle pin (channel 4); Pin 2 - Potentiometer's middle pin (channel 6); Pin 3 - A0 Arduino pin for reading value; Pin 4 - Potentiometer's middle pin (channel 7); Pin 5 - Potentiometer's middle pin (channel 5); Pin 6 - Ground (Arduino); Pin 7 - Ground (Arduino); Pin 8 - Ground (Arduino); Pin 9 - Pin 8 Arduino (address A); Pin 10 - Pin 9 Arduino (address B); Pin 11 - Pin 10 Arduino (address C); Pin 12 - Potentiometer's middle pin (channel 3); Pin 13 - Potentiometer's middle pin (channel 0); Pin 14 - Potentiometer's middle pin (channel 1); Pin 15 - Potentiometer's middle pin (channel 2); Pin 16 - 5V (Arduino);

Now we can read state of every potentiometer value using just one reading pin on Arduino (and three other pins for addressing).

Upload following code and read values in serial monitor.

show more
Step 4

Use CD4051BE as demultiplexer with Arduino

When we use CD4051BE as demultiplexer that mean to take single input signal (0 or 1) and selecting one of many data output lines, which is connected to the single input.

Example on picture shows eight LEDs control by one output pin and three address pins.

Connect multiplexer and devices pins as follow (see picture):

Pin 1 - LED positive pin (channel 4); Pin 2 - LED positive pin (channel 6); Pin 3 - 13 Arduino pin for send HIGH ot LOW value; Pin 4 - LED positive pin; Pin 5 - LED positive pin; Pin 6 - Ground (Arduino); Pin 7 - Ground (Arduino); Pin 8 - Ground (Arduino); Pin 9 - Pin 8 Arduino (address A); Pin 10 - Pin 9 Arduino (address B); Pin 11 - Pin 10 Arduino (address C); Pin 12 - LED positive pin (channel 3); Pin 13 - LED positive pin (channel 0); Pin 14 - LED positive pin (channel 1); Pin 15 - LED positive pin (channel 2); Pin 16 - 5V (Arduino);

Now we can turn on every LEDs using just one output pin on Arduino (and three other pins for addressing).

One LED can be driven in certain time. Set delay value to 1000 ms, and then change it to 1. First you will see that LEDs turning on one by one, and then you will see like all LEDs is turned on in same time. That is actually not happening, but turning on of each individual LEDs is faster then our eye can recognise.

Upload following code and see results.

show more
Step 5

Addressing

Check the truth tables on picture and you will figure out how to address individual channel.

This is actually binary logic. A bit (short for binary digit) is the smallest unit of data in a computer. A bit has a single binary value, either 0 or 1. That mean with one bit (A) we can control two channels (0 or 1). With two bits (A and B) we can address four channels. With three bits (A, B and C) we control eight channels. With every next address pin (D, E etc) number of channel control will grows exponentially. For example with just one more pin we will be able to control 16 channel multiplexer.

Pin 6 on this type multiplexer is inhibit (break). If we send address and inhibit pin is 1 we will not see any change. That is reason why we connect it directly to ground, but if you need to control this behavior you can use additional pin to send 0 or 1 to inhibit pin.

Tutorial Forum

There are no posts here yet. Add the first post