Home Chipkit Chipkit UNO and 4051 LED example

Chipkit UNO and 4051 LED example

by shedboy71

In previous posts we showed some examples for the 4067 16-Channel multiplexer – http://www.piclearning.net/132/chipkit-uno-and-4067-led-output-example.php

The HCF4051 device is a monolithic integrated circuit fabricated in MOS (metal oxide semiconductor) technology available in SO-16 and PDIP-16 packages.

The HCF4051 analog multiplexer/demultiplexer is a digitally controlled analog switch having low ON impedance and very low OFF leakage current. This multiplexer circuit dissipates extremely low quiescent power over the full VDD- VSSand VDD- VEEsupply voltage range, independent of the logic state of the control signals.

This device is a single 8-channel multiplexer having three binary control inputs, A, B, and C, and an inhibit input. The three binary signals select 1 of 8 channels to be turned on, and connect one of the 8 inputs to the output. When a logic “1” is present at the inhibit input terminal all channels are off.

Here is a pinout of the 4051

74HC4051 pinout

74HC4051 pinout

Lets look at the truth table of the 4051 which will show how this works

4051 truth table

4051 truth table

Now lets have an example, we want to flash an LED on Channel AO which is Pin 13 of the IC, in this case A0, A1 and A2 all have to be a logic 0. So with our micro we can make the pins that we connect to A0, A1 and A2 all low and that will activate channel A0. In our example we have the following wiring

A0 – Arduino D4
A1  – Arduino D5
A2 – Arduino D6

INH or Enable is tied to 0v

In the schematic below we show 1 resistor and LED only, our test board had 8 sets of resistors and LEDs connected to X0 – X7

Chipkit and 4051 led

Chipkit and 4051 led

Code

The code is actually adapted from the 4067 example. This example will cycle through all 8 channels one at a time.

 

[codesyntax lang="cpp"]
const int channel[] = {4, 5, 6};

//the output pin - mux input
const int outputPin = 7;

void setup() 
{
  // set up all pins as output:
  for (int chipkitPin = 4; chipkitPin <= 7; chipkitPin++) 
  {
    pinMode(chipkitPin, OUTPUT);
  }
}

void loop() 
{
  //iterate through the 8 channels of the multiplexer
  for (int muxChannel = 0; muxChannel < 8; muxChannel++) 
  {
    //set the channel pins based on the channel you want
    //LED on - high - 100 milliseconds delay
    muxWrite(muxChannel);
    digitalWrite(outputPin,HIGH);
    delay(100);
  }
}

void muxWrite(int whichChannel) 
{
  for (int inputPin = 0; inputPin < 3; inputPin++) 
  {
    int pinState = bitRead(whichChannel, inputPin);
    // turn the pin on or off:
    digitalWrite(channel[inputPin],pinState);
  }
}
[/codesyntax]

 

Share

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More