Experiment #3: Optimum Microcontroller LED control
Introduction
In order to minimise the number of microcontrollers required to control the diorama’s lighting and mechanical features the least possible number of microcontroller pins needed to used to control the numerous LEDs used on the diorama. This experiment was conducted to find the best method to achieve this goal.
Two different methods were tried:
- 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.
- 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.
Circuits
The two circuits are shown in the following image carousel:
These circuits differ only in two respects:
- 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.
- Different colour LEDs were used in each circuit!
Code
The code used to exercise these cicuits is available in the cahamo/diorama
project on GitHub. There are two test programs:
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.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.
Results
The following videos show the results of running the two versions of the circuit and their associated code.
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. Although the second video shows slow pulsing flickering when several LEDs are lit “together”, the reality is that 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.
Circuit
The circuit schematic is shown in the following diagram:
The circuit as tested can be seen on the following breadboard diagram:
Code
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
.
Results
The following video shows the circuit in operation:
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.
Conclusions
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.
Tests will continue with 75HC595 shift registers and the CD74HC4067 multiplexer will be abandoned.