Arduino Tutorial Demux

Use 4 Arduino pins for 16 outputs! Serial to Parallel Demultiplexer

Arduino Serial to Parallel Demultiplexer

A demultiplexer is a great way to allow you to use more output pins for your Arduino. Its purpose is to take a Serial signal and convert it to a parallel one. This functionality is extremely simple to implement and can be a great alternative to shift registers discussed in one of my other tutorials. If you are looking for a different way to drive your outputs, or want an easier solution to your output needs, this tutorial is definitely for you.

Required Hardware

For this tutorial, you will require the following:

  • Arduino
  • Breadboard
  • 4x Push Buttons
  • 16x LEDs
  • 20 Resistors – 16 Current Limiting for the LED and 4 Pull-ups for the button (Internal can also be used)
  • SN74LS154N – Datasheet Link: Click Here
  • Jumper Wires

Keep in mind that my video showcases the hardware implementation of the IC before jumping into the Arduino Serial to Parallel implementation. This means that you may not need the four push buttons if you only want to work with the Arduino.

Hardware Setup

If you go through the datasheet of the IC, you will see a pinout section. This section will describe each pin you will need to use. Make sure to connect the Vcc, Gnd pins to your power rail, G1 and G2 to ground, A, B, C and D to outputs on the Arduino and Outputs 0 – 15 to your LEDs or outputs.
Arduino Serial to Parallel Demux

What you need to pay attention to as well is the truth table. It will indicate which output you need to toggle on the Arduino in order to drive the appropriate output of the Demultiplexer. Make sure to fully understand what goes where and how everything is tied together internally. Here is the truth table from the datasheet:
Demultiplexer Truth Table

Arduino Serial to Parallel Implementation

I will go through the code section by section. If you have any questions about a specific segment, leave them in a comment below or on the forums.


int Outputs[] = {9,10,11,12};
void setup()
{
pinMode (Outputs[0], OUTPUT);
pinMode (Outputs[1], OUTPUT);
pinMode (Outputs[2], OUTPUT);
pinMode (Outputs[3], OUTPUT);
}

The above lines are used to specify our Arduino outputs which will be used in the Serial Communication.


void loop()
{
for (byte binary =0;binary<=15; binary++) { BinaryOut(binary); delay(500); } }

The main loop of our program will go through each number from 0 to 15 and output it to the function BinaryOut; a delay of 500ms is implemented in order to make the effect more visible on the microcontroller.


void BinaryOut(byte number)
{
for (int i =0;i<4;i++) { if (bitRead(number, i)==1){ digitalWrite(Outputs[i], HIGH); }else{ digitalWrite(Outputs[i], LOW); } } }

The binaryOut function converts the input into a binary signal sent to our outputs. This leads to possible outputs ranging from 0000 to 1111 on the 4 pins. As logic suggest, we can implement 2^4 outputs which is exactly the case with this demux IC.

Complete Code


int Outputs[] = {9,10,11,12};
void setup()
{
pinMode (Outputs[0], OUTPUT);
pinMode (Outputs[1], OUTPUT);
pinMode (Outputs[2], OUTPUT);
pinMode (Outputs[3], OUTPUT);
}
void loop()
{
for (byte binary =0;binary<=15; binary++) { BinaryOut(binary); delay(500); } } void BinaryOut(byte number) { for (int i =0;i<4;i++) { if (bitRead(number, i)==1){ digitalWrite(Outputs[i], HIGH); }else{ digitalWrite(Outputs[i], LOW); } } }

Thank you for reading & watching the tutorial. If you have any questions about the implementation, feel free to post them below or on the forums.
- EEEnthusiast

Comments 8

  1. Great beat ! I would like to appprentice even as you amend your website, how can i subscribe
    for a blog site? The account aided me a acceptable deal.

    I had been a little bit familiar of this your broadcast offered bright clear idea
    Diego recently posted…DiegoMy Profile

  2. Hi, just starting out with Arduino’s, have small a project in mind. I am making a Jupiter II model, and want to build the fusion core for the bottom of it. It requires a 32 LED chase array. Can I use two of the SN74LS154N you mentioned in this article? As I don’t see how to get the second chip to work without a delay when it switches on and how to switch off the first chip so that the Led 0 is not lit. Any pointers would be helpful. Thanks.

  3. hello
    i want to turn on randomly leds with arduino +decoder …can you help me what codes i should use?

  4. hello
    i want to turn on randomly leds with arduino +decoder …can you help me what codes i should use?

  5. Post
    Author

    Sorry, I just stuck with the defaults of that addon. I’ll change it for the future posts as it started to annoy me as well.

  6. Hi, I am new to the Arduino, I have a project I am working on to test wiring harness. I was wondering if you can control multiple 74hc4051 with the 74ls154n.

  7. Post
    Author

    Hi Sean,

    No, that would not work. You won’t be able to read the analog signals sent back through the digital de-mux. For more analog I/O, I would recommend an IC over the I2C bus.

Leave a Reply

Your email address will not be published.

CommentLuv badge