Experiment #3: Optimum Microcontroller LED control


In order to minimise the number of microcontrollers required to control the diorama’s lighting and mechanical features the most optimum use of microcontroller pins needs to be found when controlling LEDs. To this end, various circuits were built on breadboards in an attempt to light various combinations of LEDs using as few microcontroller pins as possible.

Two different methods were tried:

  1. A CD74HC4067 16 channel multiplexer was used to drive 16 LEDs. Two different versions of a test program were tried on two very slightly different circuits.
  2. A pair of 75HC595 shift registers were used together to illuminate various combinations of 16 LEDs.

CD74HC4067 16 channel multiplexer

This multiplexer was connected to an Arduino Uno and to 16 LEDs. Two variations were tried.


The two circuits are shown in the following image carousel:

These circuits differ only in two respects:

  1. The first circuit connects the CD74HC4067’s EN pin to the Arduino so that the CD74HC4067 can be switched on and off. The second circuit leaves the EN pin disconnected.
  2. Different colour LEDs were used in each circuit!


The code used to exercise these cicuits are available in the cahamo/diorama project on GitHub. They are:

  1. cd74hc4067-mux-led-test-1.cpp: A simple program that lights each of the 16 LEDs in turn. This program also uses the CD74HC4067’s EN pin to turn all LEDs off.
  2. cd74hc4067-mux-led-test-2.cpp: A more complex program that lights various sequences of LEDs quickly in succession to attempt to display patterns where more than one LED is lit at once.


See the following videos to see the results of running the two versions of the circuit and their associated code.

1st circuit with cd74hc4067-mux-led-test-1.cpp

2nd circuit with cd74hc4067-mux-led-test-2.cpp

The first test showed that the CD74HC4067 is useful for multiplexing LEDs when only one LED needs to be switched on at a time. However the second test, which is a more realistic scenario for the diorama, revealed that when several LEDs need to be lit simultaneously the circuit does not switch fast enough to eliminate flicker. The second video shows slow pulsing flickering when several LEDs are lit “together”, but in reality this flickering is fast and annoying.

75HC595 shift registers

Two 75HC595 shift registers were connected together and to an Arduino Uno. A program was used to light different combinations of LEDs.


The circuit schematic is shown in the following diagram:

Schematic for 75HC595 test circuit

The circuit test layout can be seen on the following breadboard diagram:

Breadboard layout of 75HC595 test circuit


The code runs through a sequence of patterns where one or more of 16 LEDs are illuminated at the same time. This is done by loading 16 bits of data into the two shift registers, where each bit determines whether an associated LED is switched on or off.

The code is available in the cahamo/diorama project on GitHub as 74hc595-x2-led-test.cpp.


The following video shows the circuit in operation:

75HC595 circuit with 74hc595-x2-led-test.cpp

Note that the circuit seen in the video was built on one breadboard, not two as shown in the above diagram.

The video reveals no LED flicker, and indeed this is the case in real life.


The requirement for the diorama is that a variable number of LEDs will need to lit at the same time, without flicker.

It is readily apparent that the CD74HC4067 multiplexer does not fit the bill due to the excessive flicker that is observed when more than one LED is lit.

The pair of 75HC595 shift registers do give the required results and an adaptation of this circuit is a more promising candidate for use on the diorama. The only downside is that the relative brightness of the LEDs will not be able to be changed using pulse width modulation, because only one PWM signal can be sent to all the currently lit LEDs. It does seem possible that overall brightness of all the LEDs could be changed together using this method, although this has not been tested.

The final conclusion is that tests will continue with 75HC595 shift registers and the CD74HC4067 multiplexer will be abandoned.

Back to main project page