Wednesday, 2 July 2014

Extremely simple multiplexing example

So in this very simple example I use the famous RGB Leds.

The LEDs have 4 legs: 3 of them are used for selecting the colour basically, applying different voltages will result in different colour tones. The 4th pin is the GND: when grounded, the LED will turn on. So, on the Arduino board, we are using 4 pins, all connected to the LED. But what if we want 2 LEDs? Do we need 8 pins? Well not necessarily.

We can use transistors to solve this problem. For this example I used NPN (BC548)

Both LEDs have the RGB legs connected to the Arduino, whereas their ground pins don't go the same way. They go to their respective transistor's collector . These transistors have their emitter pins connected to ground and the base goes to 2 different pins on the Arduino. Basically, when setting high these pins (connected to the base) we turn the transistors on and, by doing so, the LEDs are grounded and they will turn on. Now we can also select which LED we want to light up.

Here's the schematics:




Here's a short demo.


The LED colours are set for random, so they change every 500ms.

We'll see later how to obtain 2 different colours.

The code is very easy. Simply set to high the pin connected to whichever transistor you want tu turn on and use the analogWrite for the RGB pins, so you can get different colours.




No comments:

Post a Comment