loading
Picture of Multiplexing with Arduino and the 74HC595
FKCG4RPH1ZG7675.jpg
led matrix_schem.jpg
labeled schem.jpg
The 74HC595 is an easy and inexpensive (at about 60 cents apiece) way to increase the number of digital out pins on your Arduino.  In this tutorial I'll show you how to drive up to 16 LEDs with one 74HC595 using a technique called multiplexing.  In the end, all 16 LEDs will require only three of the Arduino's available digital pins.

The finished product will look like this:


I used the sparkfun button pad pcb to build my 4x4 led matrix because this is the first step in a longer project I'm working on that involves backlit buttons.  However, you can build your own 4x4 led matrix pretty easily on a breadboard, and I'll provide schematics that will show how to do that.  My parts list is given below:


Parts List:

SPARKFUN:
(1x) Button Pad 4x4 - LED Compatible Sparkfun COM-07835
(1x) Button Pad 4x4 - Breakout PCB Sparkfun COM-08033
(1x) Arduino Uno Sparkfun DEV-11021

DIGIKEY (you could find these at Jameco):
(16x) White 5mm LED (3mm is fine too) Digikey C513A-WSN-CV0Y0151-ND
(1x) 74HC595 shift register Digikey 296-1600-5-ND
(1x) 16 pin IC socket Digikey A100206-ND

JAMECO:
(1x) 16 conductor ribbon cable Jameco 28RC16-10VP
(1x) 16 pin right angle connector Jameco 746285-3
(2x) male header pins Jameco 7000-1X40SG-R

Additional Materials:
22 Gauge Wire, multiple colors Radioshack #278-1221
protoboard with copper Radioshack #276-147
wire cutters
wire strippers
solder
 
Remove these adsRemove these ads by Signing Up

Step 1: What Is Multiplexing?

Picture of What Is Multiplexing?
multiplex2.gif
Multiplexing is a very efficient technique for controlling many components wired together in a matrix/array.  In this example, I'll be talking exclusively about multiplexing an array of LEDs, but the same basic principles apply to other multiplexed components (sensors, buttons, etc).

In a multiplexed array of LEDs, only one row of LEDs is on at any given time.  It seems like this would limit the types of shapes we can display on the LED matrix, but it actually doesn't.  This is because the arduino (or whatever is sending data to the array) is switching through each row so quickly (hundreds or thousands of times a second) that we do not perceive the flashing on and off of each consecutive row.  You can read more about this phenomenon, called persistence of vision, on wikipedia.

So how do we send data to one row at a time?  If we connect five volts (red) to one row and connect ground (blue) to the other three rows and cycle through each row one by one, it will look something like figure 1.  Now image that while one of the rows is at +5, we connect one of the columns to ground.  As shown in figure 2, this will cause the LED at the junction of the +5 row and GND column to light up.  This way, we can address each of the 16 LEDs in the matrix individually using only eight leads (four to the rows and four to the columns).

Now look at the image below.  Imagine if we very quickly turn on the LED in the upper left corner (position 1,1), then the LED at (2,2), then (3,3) and (4,4), and we cycle between these four LEDs very quickly (hundreds of times a second).  It will appear that all four of these LEDs are on a the same time (as shown in right image in the image below).  Study the diagram below and convince yourself that this is true.


Step 2: How does the 74HC595 work?

Picture of How does the 74HC595 work?
Screen shot 2012-06-03 at 6.48.20 PM.png
led matrix_schem.jpg
labeled schem.jpg
The 74HC595 is an 8 pin shift register.  Shift registers are chips which use logic gates to control many inputs or outputs at once.  They are inherently digital, like the digital pins on the arduino- this means that they can only read or write 0V and 5V (low or high), they should not be used to read analog data from sensors or potentiometers (instead consider using a mux/demux such as the 4051).  The 74HC595 has 8 outputs labeled Qa-Qh (or Q0-Q7), it cannot read data from these pins, they can only be used as outputs (if you are looking for a shift register with inputs check out the 74HC165).

The 74HC595 is controlled by three connections to the arduino (or your microcontroller of choice); they are called the data pin, latch pin, and clock pin.  Refer to the flow diagram above (figure 1):

-first the latch pin is set to ground to disable the outputs, this way the output pins won't change as we are sending in new data to the 74HC595
-next new data is sent to the 74HC595 serially, by pulsing the clock pin and sending each byte of new data out the data pin bit by bit.  Arduino has a handy function in their library called shiftOut that takes care of this for you.
-finally, set the latch pin high.  This sends your new data to all the output pins at once (parallel output).

In this tutorial I'll show you how to control a 4x4 LED matrix with one 74HC595.  In the previous step I showed that it is possible to control a 4x4 LED matrix using only 8  pins (four for the rows and four for the columns).  In the next steps I'll show you how to wire the 4x4 LED matrix to the 8 output pins of the 74HC595 and drive the entire thing with the arduino.

One more thing to add about the 74HC595:
It is also possible to expand your outputs even further by daisy chaining 74HC595, but that is outside the scope of this tutorial.

Step 3: Schematic

Picture of Schematic
labeled schem.jpg
Screen shot 2012-05-08 at 7.06.05 PM.jpg
Screen shot 2012-05-08 at 7.04.46 PM.jpg
The images above show the schematic for the LED matrix and 74HC595 circuit.  The labels in fig 2 correspond to the labels on the sparkfun button pad.  Figure 3 is the pin diagram of the 74HC595 from the chip's datasheet.

Arduino Pin Connections to 74HC595

A0    Clock Pin (pin 11)
A1    Latch Pin (pin 12)
A2    Data Pin (pin 14)

Step 4: Solder LEDs to Sparkfun PCB

Thread the leads of 16 LEDs (5mm or 3mm are fine, I used 5mm) through LED holes in the sparkfun PCB.  These boards are compatible with 4 lead RGB LEDs, so there are four available holes on each button pad.  You can use the two center holes for single color LEDs (see figure 3).  Be sure that the flat edge of the LED (the cathode) lines up with the flat marking on the PCB.

Solder the LED leads and cut away the excess wire.

If you do not have a sparkfun PCB:
See figures 7 and 8 for the LED matrix wiring diagram.  Connect the anodes (long lead) of each row of LEDs together and the cathodes (shorter leads) of each column of LEDs together in the matrix.

Step 5: Ribbon Cable

Picture of Ribbon Cable
IMG_3426 copy.jpg
IMG_3425 copy.jpg
IMG_3428 copy.jpg
led matrix_schem.jpg
labeled schem.jpg
Cut about 1ft of 16 conductor ribbon cable. Separate and strip the ends of all 16 wires on one side and solder to Sparkfun PCB.  The following list gives all the colored conductors in order with the name of the PCB hole they should be soldered to, if you do this correctly none of the wires should cross.  Note that since I'm only using a single color LED, I'll wire up only the "blue" anode.

See the labels on the schematics above for reference (esp if you are not using the sparkfun pcb).

Connections:

one side of ribbon cable
Brown         SWT-GND1
Red             LED-GND1
Orange       SWT-GND2
Yellow         LED-GND2
Green         SWT-GND3
Blue            LED-GND3
Purple         SWT-GND4
Grey            LED-GND4
White          BLUE4
Black           SWITCH4
Brown         BLUE3
Red             SWITCH3
Orange       BLUE2
Yellow         SWITCH2
Green         BLUE1
Blue            SWITCH1
other side of ribbon cable

Step 6: Clamp Socket

Picture of Clamp Socket
IMG_3432 copy.jpg
IMG_3433 copy.jpg
IMG_3434 copy.jpg
IMG_3436 copy.jpg
Use a bench vice to clamp 16 pin socket on ribbon cable.  If you do not have a bench vice do not use pliers do this, you will clamp the socket on sideways and mess up the connections.  You're better off using a hammer to tap the clamp shut, just make sure you are always applying pressure evenly across the socket.

Be sure the clamp the socket on the ribbon cable in the same orientation indicated in the images above.

Step 7: Header Pins

Picture of Header Pins
IMG_3517 copy.jpg
Solder two rows of eight header pins to the protoboard.  This is where the ribbon cable socket will attach to the board.

Step 8: Current Limiting Resistors

Picture of Current Limiting Resistors
IMG_3522 copy.jpg
multiplex2.gif
labeled schem.jpg
The 74HC595 will be driving the LEDs in the sparkfun board.  However, this chip only outputs 0 or 5V and it can output as much as 70mA per pin.  This means we must use current limiting resistors to prevent damaging the LEDs.  Find the resistors connected to the cathodes of the LED matrix in the schematic (fig 4).

From the specs of the LEDs I used:
max forward current: 30mA
forward voltage: 3.2V

Calculate the resistance needed to achieve these max ratings from V = IR:
resistance = (5V-3.2V) / (0.03A)
= 60 ohms

It's not a good idea to actually use 60ohm resistors, you could damage the LEDs.  We also need to take into account the fact that the 74HC595 can only source up to 70mA per output pin.  Since we are multiplexing, a maximum of four LEDs can be on at any time (the entire row can light up at once).  If we use 60ohm resistors then all four LEDs together would draw 120mA (30mA *4) of current at once from their common anode.  This probably wouldn't damage the 74HC595 immediately, but it would cause noticeable dimming of the LEDs.  I chose to use 120ohm resistors instead; this way four LEDs can only draw a max of 60mA (15mA*4) at a time.

note- I made a mistake a grabbed the 100KOhm resistors when I first soldered this project together, I fixed it later, but the stripes of 120Ohm resistors should be brown, red, brown, gold, ignore the colors in the images.

These are the sample calculations for the specific LEDs I used, you'll need to do you own calculations based on the specs of your LEDs.  If you are unsure of what to do, use 220ohm or higher resistors; using too much resistance will make the LEDs less bright, but they will not be damaged.

Solder four resistors to the protoboard as shown in the images above.  Connect the leads of the resistors to their adjacent header pins with solder (figure 2).

Step 9: 74HC595 Socket

Picture of 74HC595 Socket
IMG_3532 copy.jpg
Solder an 8-pin socket to the protoboard as shown in the images above.  It's always a good idea to use a socket for ICs; it prevents damaging the IC from the heat of the soldering iron and the IC can easily be removed and replaced if needed.

Step 10: Connections to LEDs

Picture of Connections to LEDs
IMG_3534 copy.jpg
IMG_3536 copy.jpg
IMG_3535 copy.jpg
led matrix_schem.jpg
labeled schem.jpg
The output pins (Qa-Qh) are located on pins 1-7 and 15 of the 74HC595.  Connect the resistors to pins 4-7 with jumper wires as shown in figures 1 and 2.  Connect the male header pins to pins 1-3 and 15 as indicated in figs 3 and 4 (see the note on the image- I made a mistake while soldering, refer to schematic and info below for proper wiring).  Make sure to electrically join all these connections with solder on the underside of the board (figs 2 and 4).

As indicated in the schematic, the pin connections are as follows:

top
row 1  (or "blue 1")        QD(3)
row 2  (or "blue 2")        QC(2)
row 3  (or "blue 3")        QB(1)
row 4  (or "blue 4")        QA(15)
bottom

left (if you are facing the front of display/looking into the LEDs)
column 1  (or "led gnd 4")   QH(7)
column 2  (or "led gnd 3")   QG(6)
column 3  (or "led gnd 2")   QF(5)
column 4  (or "led gnd 1")   QE(4)
right

Step 11: Arduino

Picture of Arduino
led matrix_schem.jpg
labeled schem.jpg
Solder header pins to breadboard so that Arduino Uno will snap to the board.  You may need to bend some of the header pins with pliers to get a good fit (fig 1).

Connect the three 74HC595 data pins to arduino analog in 0, 1, and 2 according to the schematic.  Connect pins 8 and 13 of the 74HC595 to arduino ground and pins 10 and 16 of the 74HC595 to Arduino 5V.

Arduino Pin Connections to 74HC595

A0    Clock Pin (pin 11)
A1    Latch Pin (pin 12)
A2    Data Pin (pin 14)

Step 12: Firmware

Picture of Firmware
led matrix_schem.jpg
labeled schem.jpg
Upload the code below onto the arduino and test to see if LEDs are wired correctly.  Insert the 74HC595 into the empty socket, plug the sparkfun pcb ribbon cable into its socket, and connect the arduino to the protoboard.  You should see each LED light up one at a time, this loop will continue repeating forever (see video below).  See comments in code and step 3 for more info on how this works.


For more information on the 74HC595 and shiftOut, see fig 2, the datasheet, and the arduino reference page.

Step 13: More Firmware

Picture of More Firmware
IMG_5381 copy.jpg
IMG_5380 copy.jpg
led matrix_schem.jpg
labeled schem.jpg
The previous code was a good example of how to address each led one at a time, I slowed down the speed that the 74HC595 cycles through each pin so that you can really see each led by itself.  But the real purpose of multiplexing is to cycle through each row very quickly and address the whole matrix at once.

In the code below, I set up the array "ledData".  Each number in ledData corresponds to a row of LEDs in the 4x4 matrix.  The first number (by default 1) corresponds to the top row, the second number (by default 3) to the second row, and so on.... The values in ledData can range from 0 - 15, where 0 is all LEDs off in that row and 15 is all LEDs on in that row.  You can get any combination of off and on LEDs by finding its binary equivalent and storing this value in the array ledData.  The default values in ledData will generate the pattern shown in figure 2.  Try changing the defaults and see the results, by changing ledData to {5,3,7,15} I generated the pattern shown in figure 3.

Step 14: Shift Out

Picture of Shift Out
In the previous two steps I used the arduino function shiftOut to send data to the 74HC595, but there may be some times when you want to have a little more control over the sequence of events in your code.  Below is some code which does the same thing as in the last step (sends data from ledData to LEDs), but this code only uses digitalWrite() commands.


1-40 of 47Next »
BogdanM31 month ago

i have aded another 74HC595 so i have 8x8 matrix. I managed to make each led light up on it's own like in the first video but i am having trouble to modify the last code. Can anyone help ?

JacekP made it!1 month ago

Just a POC but I did it :]

very good instructable thank you!

Am I wrong or with the 10x10 matrix setup and using BCM it's not possible to create change each LED brightness independently?

It looks like there might be too many operations to be executed within too short time frame :/

or...?

IMG_0518.JPG
redsox1218754 months ago

Could this hold enough current to run no more than four 10mm brushless vibration motors at once? They are model: 910-101

Nighter3D1 year ago

Ugh...this IC has caused far more Headache then any other T_T

The thing is that the Chip itself is rated to a maximum current of 70ma in total, meaning that to drive more then a few Leds or such at a time is suicidal...And yet in Practice the chip seems to hardly break a sweat. this has resulted in a fissure between people saying it CAN and others that keep yelling it will Burn.

Personally Ive come up with the theory that people should take the datasheet with a grain of salt. It says 70ma in current perhaps, but it never specified if its the actual same voltage which in the end together with the current defines the actual Power in Watt being drained/sourced. Heck i have one right besides me that seems able to Drive a Numitron tube that draws 20ma at 3.3v with ease!

Great IC...although better clarity at its maximum should be looked into by the manufacturers...or whoever designed the first one of which all manufacturers have copied the design off.

JakeD5 Nighter3D6 months ago

If you want more current coming out of the 595, hook them up to transistors for lower current, or for higher current, you could use a relay.

mrouse257 months ago
We don't perceive all of the LEDs to be on at once because of persistence of vision, we do because of flicker fusion.

You linked to the persistence of vision wiki article and in the first paragraph it clearly states that the perception of continuous light is due to flicker fusion...
The same reason why we don't see a common light bulb flicker on ac electricity

Great project! I've been messing with this myself. Were you able to get a RGB led working with this board?

amandaghassaei (author)  cookieman4591 year ago

haven't tried yet, should be no problem if you copy this circuit 3x

The issue I have had is with the matrix being based on ground. When I tried this X3 it caused all sorts of weirdness since the ground connection (I think) created a lot of closed circuits that shouldn't be closed. Basically lots of extra lights and colors. I couldn't get any isolation like X1 worked.

It's also quite possible I just did something stupid. Possibly I need some more diodes in the design to prevent some crossflow.

I just managed to get this working with common-cathode RGB LED matrix, with the help of a friend, and based on this: http://alvarorevuelta.net/the-core-of-midispositi... .

Basically, you need to connect all of the power and clock lines up in parallel, and connect the serial out (Q7') from the first chip to the serial in (DS) on the second chip (so you don't need to use any more pins on the arduino). Then you hook up sets of 4 parallel outs to the matrix. Now you need to send two separate bytes. The first byte will be send to the *second* chip, and the second byte to the one connected directly to the arduino.

I had troubles with interference - use filter caps between the VCC and GND pins of each chip.

If someone is interested, you can check out the whole project here (using the sparkfun pcb): http://alvarorevuelta.net/midispositivomidi/

ChrisR311 months ago

Alternatively you may consider using a dual 2-to-4 line decoder (I just recently discovered these things existed):

http://www.nxp.com/documents/data_sheet/74HC_HCT13...

use two lines to specify the row, and two lines to specify the column. This skips the serial-to-parallel translation stage with the shift register, at the cost of one extra line.

I would like to point out to the entire universe that what everyone is calling multiplexing is in reality DE-Multiplexing.

I don't know how or when it all got confused, but everyone is doing it now, and it kinds bugs me!

Multiplexing is when you take a large number if signals, and combine them into a few lines. A good example of this is when 500 apartments in an apartment building all have their telephone lines connected by one fibre optic line to the phone company. De-multiplexing happens when the fibre optic line comes back to the apartment and then becomes 500 individual phone lines. So what we are really doing with our microcontrollers sending out data that gets spread across a much larger number of devices or wires (LEDs usually) is de-multiplexing. If we were to take 250 push-buttons and connect them all to the Arduino with 2 wires so that it could tell which button was pressed, that would be multiplexing.

That said - Nice project!

I too, like to use the correct terms when explaining, and I understand your frustration, but this instructable is geared more for beginners, so "multiplexing" makes it easier to understand.

Actually it is neither multiplexing or demultiplexing. You could consider it a DEMUX because it is a serial to parallel conversion, but each output is staggered based on the clock (so it is 8 in 8 out --kinda/sorta), which doesn't occur using MUX or DEMUX. The best term I can come up with is "Serial In to Parallel Out Shifted", which is awkward and wordy. Because it appears to multiply the output (persistence of vision), multiplexing is a (wrong) but better explanation.

Serial to parallel conversion is the most common form of demultiplexing.

The outputs do not have to be simultaneously active and actually rarely are.

Take the 74HC138 or 74HC238 which based on a binary number, demultiplex the single bit input to one of it's 8 outputs. Only one of the 8 outputs is ever active at once by design, and it is a demultiplexer. You can send 10,000 bits to output 1, and then send 10 bits to output 5 and then send 2 bits to output 6 - but it's still demultiplexing by definition.

Since I no longer am employed in electronics, I don't know enough to give you a good argument. My last formal schooling was building 555 timer circuits using transistors, caps, etc.; logic gates from diodes. :) Troubleshooting tube based radios. (Anybody know about the ARC51 and tuning using sharpened wooden rods?) Fun Fun. (Navy Schools). Now it just a hobby, after leaving the Corps in '97.

Now I am on the software side of IT. (DOTNET rules!) Not to impose on Linux followers, I have a UBUNTU stick whenever I want to experiment, and I first started programming using LAMP.

Those two chips you referenced look to me that they are all composed of logic gates. Some outputs look staggered, but I don't see a clock signal. Is this delay intentional, or just a side affect?

I don't know what you mean by delay - the only delay these chips might have is the tiny insignificant amount of propagation delay between input and output - otherwise it's pretty much instantaneous. The chips I mentioned have no clock. There are 2 inverted enable lines, 1 non-inverted enable line, any of which could be considered the "data" being presented at the output. If the inverted enables are grounded, and the other enable is at +v, then a "1" will be at whatever address is presented to the 3 address bits.

Yes, if you wanted to, you can break just about anything down into discrete gates, and if you did that with this chip, it would look like this for the 74HC238 (invert the outputs for the 138).

74XX238 logic.jpg

If you wanted this chip to distribute data evenly across the 8 outputs with respect to a clock, then all you'd have to do is connect the non inverted enable to your "data" bit, and put the clock into a counter like a 74HC393 and use 3 bits of the counter's output as the address bits going into the 238's address lines. Since the 2 counters in the 393 are 4 bits, we would simply tie the 4th bit of the counter we are using to the reset line so that it becomes a 3 bit counter. VOILA, multiplexed serial in to 8 demultiplexed serial out.

Thanks for the clarification, but if I had to explain the difference to my wife, it would go right over her head and simplify via this Instructable.. :)

As far as the ARC-51 goes, I never thought about Googling it, as all of our pubs (at the time) were classified material. Maybe since they have been phased out you can now download the schematics.

http://members.home.nl/a.k.bouwknegt/index_bestand I wish I had that resource back in the 80's instead of digging through 5 inch binders. :) Kinda cool. Now if I can find that power supply schematic for an APX100 (IFF) that supplied 2000VDC (my guess but I know it was over a thousand volts) from aircraft power. I still have a scar from that little bugger, it was smaller than an ATX PS. Burned a hole right through my palm. If you can find it, it had one card that was composed entirely of diode gates.

Again, thanks for taking the time to reply and clarify!

It would have been diodes and capacitors, because what you are describing is a simple voltage multiplier. A scaled down schematic is here...

Voltage Multiplier.jpg

Finally found the original manual that I used daily. I can't upload it because it is over 800 pages. I downloaded it, closed my browser, but now I can't get back in. But if you go to http://www.liberatedmanuals.com and do a search for NAVAIR 16-30APX72-2 it should let you view it. That site limits the amounts of downloads/day. Here is a functional diagram and a schematic (sorry a bit fuzzy).

APX100PS_FuncDiag.pngAPX100PS.png

Well, I think we have strayed far enough off topic on this poor man's thread.

This started out as multiplexing VS demultiplexing, so I think I am just going to terminate our personal sideline here. If you wish to keep discussing things like this, then you can inbox me or post on my orangeboard.

I need to get back to work on my RGB LED cube PC boards anyways.

As an aside, I don't think many here have ever seen an ARC51 tranceiver.

bondike1 year ago

And how does that work with PWM "data"? Can registers "remember" the pulse width?

amandaghassaei (author)  bondike1 year ago

you can't do pwn output with a 74HC595, check out the tlc5940 instead

zmarotta1 year ago
Awesome! Any idea how I can do this with 100 RGB LEDs? :)
//LED TEST 2 w/ 74HC595
//by Amanda Ghassaei 2012
//http://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/

/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

//this code will display the values of ledData across a 4x4 led matrix

//pin connections- the #define tag will replace all instances of "latchPin" in your code with A1 (and so on)
#define latchPin A1
#define clockPin A0
#define dataPin A2

//looping variables
byte i;
byte j;

//storage variable
byte dataToSend;

//storage for led states, 4 bytes
byte ledData[] = {1, 3, 7, 15};

void setup() {
//set pins as output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {

for (i=0;i<4;i++){

//send data from ledData to each row, one at a time
byte dataToSend = (1 << (i+4)) | (15 & ~ledData[i]);

// setlatch pin low so the LEDs don't change while sending in bits
digitalWrite(latchPin, LOW);
// shift out the bits of dataToSend to the 74HC595
shiftOut(dataPin, clockPin, LSBFIRST, dataToSend);
//set latch pin high- this sends data to outputs so the LEDs will light up
digitalWrite(latchPin, HIGH);

}
}

//LED TEST 2 w/ 74HC595
//by Amanda Ghassaei 2012
//http://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/

/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

//this code sends data to the 74HC595 without "shiftOut"

//pin connections- the #define tag will replace all instances of "latchPin" in your code with A1 (and so on)
#define latchPin A1
#define clockPin A0
#define dataPin A2

//looping variables
byte i;
byte j;

//storage variable
byte dataToSend;

//storage for led states, 4 bytes
byte ledData[] = {1, 3, 7, 15};

void setup() {
//set pins as output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {

for (i=0;i<4;i++){

//send data from ledData to each row, one at a time
byte dataToSend = (1 << (i+4)) | (15 & ~ledData[i]);

// setlatch pin low so the LEDs don't change while sending in bits
digitalWrite(latchPin, LOW);

// // shift out the bits of dataToSend to the 74HC595
// shiftOut(dataPin, clockPin, LSBFIRST, dataToSend);
// the code below is the equivalent of the two lines above
for (j=0;j<8;j++){
digitalWrite(clockPin,LOW);
digitalWrite(dataPin,((dataToSend>>j)&1));
digitalWrite(clockPin,HIGH);
}


//set latch pin high- this sends data to outputs so the LEDs will light up
digitalWrite(latchPin, HIGH);

}
}
sanjoseph1 year ago
arabic letters!!! do u have any idea if is there any software used with arduino to blink led screen????
sanjoseph2 years ago
thanx dear for answer...
because i am new to work with arduino...
i have some problems about alphabet [][] function cuase i dont know how does work and how it generate litters and how can i generate latin words by using ascii???
best regards....
amandaghassaei (author)  sanjoseph1 year ago
what letters do you want to make?
amplex2 years ago
I'm guessing we could use 3 74HC595 circuits with an arduino to control RGB LED's that this board was intended for use with? If we had 9 analog pins on an standard arduino that is. If we could use the same clock pin for all 3, that would cut down the pins to 7. It looks like a Mega would be the only way to make this happen.
sanjoseph2 years ago
dear sir...
u have explained 4*4 led matrix connected to arduino..
but i dont have any idea how to connect 8*8 leds using 74hc595 to arduino???any help plz
amandaghassaei (author)  sanjoseph2 years ago
same idea, but you need two 74hc595 - one connects to the 8 rows and the other to the eight columns.
ignatiusD2 years ago
Hi, I've been reading about muxing and things, and the title of this instructable is kind of confusing to me because if I'm not mistaken you're using a shift register, not a multiplexer. Is there not a significant difference?
amandaghassaei (author)  ignatiusD2 years ago
the terminology is kind of ambiguous, a shift register implies something digital, like the chip I'm using. Multiplexing in general is this technique of controlling an array, a multiplexor is something that does the multiplexing. often people refer to analog chips as mux/demux and digital as shift registers, but they both do multiplexing.
TAGAPAW2 years ago
Hi It's really Nice Instructables, but can this method to light up up to 120 button simultaneously , thank you very much
amandaghassaei (author)  TAGAPAW2 years ago
yes, definitely.
Great Instructable!
One this I am a bit confused about. What is you want to light more than one LED at once.
Wouldn't this cause some other lights to illuminate unexpectedly using this method?
1-40 of 47Next »