1

I'm attempting to use the multiplexer setup in this article with my Arduino Uno to control the output of LED's, as a way to fully understand the principles of multiplexing.

I'm working to modify the code in the article to switch from reading potentiometer values to writing voltage values to the LED's.

Below is the modified sketch; the biggest modified change is the loop in the writeMux function:

//Mux control pins
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;

//Mux in "SIG" pin
int SIG_pin = 3;

//Voltage value to write to the LEDs
int testValue = 255;


void setup(){
  pinMode(s0, OUTPUT); 
  pinMode(s1, OUTPUT); 
  pinMode(s2, OUTPUT); 
  pinMode(s3, OUTPUT); 
  pinMode(SIG_pin, OUTPUT);

  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);
}


void loop(){
  for(int i = 0; i < 9 ; i ++){
    delay(1000);
    writeMux(i);    
  }
}


int writeMux(int channel){
  int controlPin[] = {s0, s1, s2, s3};

  int muxChannel[10][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
    {1,1,0,0}, //channel 3
    {0,0,1,0}, //channel 4
    {1,0,1,0}, //channel 5
    {0,1,1,0}, //channel 6
    {1,1,1,0}, //channel 7
    {0,0,0,1}, //channel 8
    {1,0,0,1}, //channel 9
//    {0,1,0,1}, //channel 10
//    {1,1,0,1}, //channel 11
//    {0,0,1,1}, //channel 12
//    {1,0,1,1}, //channel 13
//    {0,1,1,1}, //channel 14
//    {1,1,1,1}  //channel 15
  }; 

  //loop through the 4 sig
  for(int i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  //read the value at the SIG pin
  analogWrite(testValue, SIG_pin);  

  //return the value
  return 0;
}

Below is a photo of my circuit:

However, none of the LED's light up.

I'm fairly certain that this is more of a problem with the code rather than the circuit...any advice is appreciated!

enter image description here

enter image description here

2

According to the analogWrite() documentation, apparently the trouble are that you have swapped the args.

The syntax are analogWrite(pin, value), so, the piece

//read the value at the SIG pin
analogWrite(testValue, SIG_pin);  

may work if you simply change to

//read the value at the SIG pin
analogWrite(SIG_pin, testValue);  

That with respect to code, and i hope it helps you. At the other hand, the circuit, may be a bit dangerous (and can damage the Arduino or the mux) to use LEDs without a current limiter series resistor (330 - 1K Ohm would be nice values, 1/4 W). At least, by a light sight in a datasheet of the CD74HC4067, shows max currents of +/- 25 mA per pin. Similar currents can be driven by the Arduino (Atmega 328P).

So, all depends on the internal construction of the 4067, if are a transparent mux, maybe just with a single resistance in the SIG_pin in that range of resistances, would be fine.

Edit - Some Circuit Troubleshooting

There are some other little tests that you can do after that change in code:

  1. Open the wire that goes from the Arduino to the common of the mux, then place at the output of the same Arduino pin, a LED-resistor series. Then change in program only the value of testvalue at the beginning of the code and check if the led changes their intensity according to that. That would be an Ok for that pin of the Arduino.
  2. Reply the previous step to each of the channel pins. According to the code, you should see an increasing 1 Hz, 4 bits counter (rather, a BCD counter) in thet formed 4 led array. That would be an OK for the channel selection pins.
  3. Remove the leds and connect back the opened lines.

Any fail in steps 1 or 2 may indicate that the pin are damaged but you can use another analog pin and other pins for the channels respectively. But if at step 3 it doesn't works, may be a damaged 4067 or a little hidden bad connection...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.