One of the limitations of Arduino is the fixed number of input pins available on the boards. Using a multiplexer it is possible to get Arduino additional input pins by using the digital output pins.

I brought this multiplexer from sparkfun (16-Channel Analog/Digital Multiplexer/Demultiplexer CD74HC4067) for $5 conveniently on a breakout board.

It works by connecting 4 digital output pins and 1 analog input pin. Setting high or low values on the output pins allows you to change one of 16 inputs the multiplexer can read. The output pins are read as binary. E.g. if you set all the arduino digital output pins to low, you would get 0000 = 0 so you would read pin 1 of the 16 analog input pins on the multiplexer. Similarly if you set the first 2 pins to low and the second 2 to high, it would read binary 0011 = 3 so you would read pin 3.

The circuit diagram below show you how you would wire this component:

Arduino Multiplexer
Arduino Multiplexer

I wont include full code to read the multiplexer unless requested but the bullet point steps below explain the process:

  • In the setup() method set up 4 output digital pins and 1 input analog pin.
  • create a method such as int readMultiplexor(int pin). In this method create code that maps this pin value to the setting of the 4 output pins (You could use a 2d array for this. 16 rows of 4 output values).
  • read the analog input pin value and return it.
  • In the loop() method you can print the values of each pin before sleeping.


Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *