I have this code to change channels.

void setMuxChannel(byte channel) {
   digitalWrite(muxS0, bitRead(channel, 0));
   digitalWrite(muxS1, bitRead(channel, 1));
   digitalWrite(muxS2, bitRead(channel, 2));
   digitalWrite(muxS3, bitRead(channel, 3));

I have this code to write a value in a channels, but when I change to a new channel, the previous channel returns to LOW. I want to turn on LEDs using multiplexer, however the LEDs do not stay on since the channel they are connected to does not keep its value.

  digitalWrite (muxSIG,a);
  digitalWrite (muxSIG,b);
  digitalWrite (muxSIG,c);
  digitalWrite (muxSIG,d);
  • What are the values of the variables a to d? And what LEDs? How have you connected them? Provide a schematic for this
    – chrisl
    Jun 6 '18 at 13:55
  • 1
    You don't want a mux for this job. A shift register would be better.
    – Majenko
    Jun 6 '18 at 14:11
  • 1
    You can't do that with a multiplexer, unless you scan across all channels really fast.
    – tttapa
    Jun 6 '18 at 14:18

The whole point of a multiplexer is to only connect ONE channel at a time to the input. It is designed to send many different signals through one wire by time sharing. Normally data in some form is send, and not the direct control current of a simple load. So you will not be able to drive more than one channel at a given time.

You can cycle very fast through the channels to let it seem, as if the LEDs were on simultaneously, but this will decrease their light intensity.

If you just want to drive some LEDs without using too mich of the IO pins, you should follow Majenkos comment and use a shift register instead. They can drive all outputs at the same time if wanted. Also often they can be daisy-chained to simply controlling multiple shift registers through a single output of the Arduino.

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.