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:

(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

(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

Step 1: What Is Multiplexing?

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?

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

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

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).


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

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

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

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

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

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:

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)

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)

Step 11: Arduino

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

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

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

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.

<p>So Q0-Q7 can be either 5v or GND? Should I then use N-channel or P-channel mosfet better?</p>
<p>Could this hold enough current to run no more than four 10mm brushless vibration motors at once? They are model: 910-101</p>
<p>If I were you, I'd attach the outputs of this IC to the base pins of transistors, not driving the motors directly. That's because motors often require more amps. The transistors could handle that across their collector-emitter pins, the IC itself could not.</p>
<p>Beautifully commented code dude.</p>
<p>Dudette even!</p>
<p>Seriously it warms the cockles of my heart to see someone take as much time with their comments as they do with their code, more even. The comments are more important and are completely ignored by the compiler, it's good manners and appreciated.</p>
<p>Hi there, <br>The codes aren't available any more. Any chance for an update or source?<br>Thx! </p>
<p>Hi, thanks for posting.</p><p>I used the code to drive 4 rows and 4 columns on my 8*8 matrix, as i could not find a good 8*8 based 74HC595 solution. Then I took it from there to implement a serialized implementation (2x 74HC595) to get all the 8 rows and columns going. </p><p>Took a while but i got it to work :-) I will try to post my solution later.</p><p>Thanks again!</p><p>I then adjusted it to drive the whole 8*8 matrix.</p>
<p>Hey MarkKI,</p><p>could you please send me the code you used.</p>
<p>Ugh...this IC has caused far more Headache then any other T_T</p><p>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.</p><p>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!</p><p>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.</p>
<p>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.</p>
<p>If you want to supply more current then hook the 74HC595 up to an IRF1405 N-Channel Power Mosfet which will supply ~100Amps if you use a good heatsink. Or use an IRF4905 P-Channel Power Mosfet which will handle ~50Amps if you use a heat sink. Mosfets are good because they are high impedance devices and don't require much power to switch them on. *Latching* relays are very good too if you know how to configure them properly because when they are switched on they don't use any power at all to keep them switched on. They are just like an SCR [thyristor], because once they are switched on, SCRs stay switched on too until disconnected from the power supplying them.</p>
We don't perceive all of the LEDs to be on at once because of persistence of vision, we do because of flicker fusion.<br><br>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...<br>The same reason why we don't see a common light bulb flicker on ac electricity<br>
<p>If you want to see the effect of persistence of vision with multiplexed LEDs then just blow air through your closed lips [whilst looking at a multiplexed 7 segment LED digital display] so that your lips vibrate strongly [making a sound like noisy sewing machine etc.]. Doing this makes your eyeballs dance about and you'll see each LED segment dance up and down too. Try to vary the frequency that your lips vibrate for best effect.</p>
<p>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 ?</p>
<p>Just a POC but I did it :]</p><p>very good instructable thank you!</p><p>Am I wrong or with the 10x10 matrix setup and using BCM it's not possible to create change each LED brightness independently?</p><p>It looks like there might be too many operations to be executed within too short time frame :/ </p><p>or...?</p>
<p>Great project! I've been messing with this myself. Were you able to get a RGB led working with this board?</p>
<p>haven't tried yet, should be no problem if you copy this circuit 3x</p>
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. <br><br>It's also quite possible I just did something stupid. Possibly I need some more diodes in the design to prevent some crossflow. <br><br>
<p>I just managed to get this working with common-cathode RGB LED matrix, with the help of a friend, and based on this: <a href="http://alvarorevuelta.net/the-core-of-midispositivomidi/" rel="nofollow"> http://alvarorevuelta.net/the-core-of-midispositi...</a> .</p><p>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. </p><p>I had troubles with interference - use filter caps between the VCC and GND pins of each chip. </p>
<p>If someone is interested, you can check out the whole project here (using the sparkfun pcb): http://alvarorevuelta.net/midispositivomidi/</p>
<p>Alternatively you may consider using a dual 2-to-4 line decoder (I just recently discovered these things existed):</p><p><a href="http://www.nxp.com/documents/data_sheet/74HC_HCT139_CNV.pdf" rel="nofollow">http://www.nxp.com/documents/data_sheet/74HC_HCT13...</a></p><p>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.</p>
<p>I would like to point out to the entire universe that what everyone is calling multiplexing is in reality DE-Multiplexing.</p><p>I don't know how or when it all got confused, but everyone is doing it now, and it kinds bugs me!</p><p>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.</p><p>That said - Nice project!</p>
<p>I too, like to use the correct terms when explaining, and I understand your frustration, but this instructable is geared more for beginners, so &quot;multiplexing&quot; makes it easier to understand.</p><p>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 &quot;Serial In to Parallel Out Shifted&quot;, which is awkward and wordy. Because it <strong>appears </strong>to multiply the output (persistence of vision), multiplexing is a (wrong) but better explanation.</p>
<p>Serial to parallel conversion is the most common form of demultiplexing.</p><p>The outputs do not have to be simultaneously active and actually rarely are.</p><p>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.</p>
<p>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.</p><p>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.</p><p>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?</p>
<p>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 &quot;data&quot; being presented at the output. If the inverted enables are grounded, and the other enable is at +v, then a &quot;1&quot; will be at whatever address is presented to the 3 address bits.</p><p>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). </p>
<p>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 &quot;data&quot; 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. </p>
<p>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.. :) </p><p>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. </p><p><a href="http://members.home.nl/a.k.bouwknegt/index_bestanden/ARC51_UHF_Transceiver.htm" rel="nofollow">http://members.home.nl/a.k.bouwknegt/index_bestand</a> 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.</p><p>Again, thanks for taking the time to reply and clarify!</p>
<p>It would have been diodes and capacitors, because what you are describing is a simple voltage multiplier. A scaled down schematic is here...</p>
<p>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).</p>
<p>Well, I think we have strayed far enough off topic on this poor man's thread.</p><p>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.</p>
<p>I need to get back to work on my RGB LED cube PC boards anyways.</p>
<p>As an aside, I don't think many here have ever seen an ARC51 tranceiver.</p>
<p>And how does that work with PWM &quot;data&quot;? Can registers &quot;remember&quot; the pulse width?</p>
<p>you can't do pwn output with a 74HC595, check out the <a target="_blank" href="http://playground.arduino.cc/learning/TLC5940#.Uy4ORF6SIpM">tlc5940</a> instead</p>
Awesome! Any idea how I can do this with 100 RGB LEDs? :)
//LED TEST 2 w/ 74HC595 <br>//by Amanda Ghassaei 2012 <br>//https://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/ <br> <br>/* <br> * This program is free software; you can redistribute it and/or modify <br> * it under the terms of the GNU General Public License as published by <br> * the Free Software Foundation; either version 2 of the License, or <br> * (at your option) any later version. <br> * <br> * This program is distributed in the hope that it will be useful, <br> * but WITHOUT ANY WARRANTY; without even the implied warranty of <br> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the <br> * GNU General Public License for more details. <br>*/ <br> <br>//this code will display the values of ledData across a 4x4 led matrix <br> <br>//pin connections- the #define tag will replace all instances of &quot;latchPin&quot; in your code with A1 (and so on) <br>#define latchPin A1 <br>#define clockPin A0 <br>#define dataPin A2 <br> <br>//looping variables <br>byte i; <br>byte j; <br> <br>//storage variable <br>byte dataToSend; <br> <br>//storage for led states, 4 bytes <br>byte ledData[] = {1, 3, 7, 15}; <br> <br>void setup() { <br> //set pins as output <br> pinMode(latchPin, OUTPUT); <br> pinMode(clockPin, OUTPUT); <br> pinMode(dataPin, OUTPUT); <br>} <br> <br>void loop() { <br> <br> for (i=0;i&lt;4;i++){ <br> <br> //send data from ledData to each row, one at a time <br> byte dataToSend = (1 &lt;&lt; (i+4)) | (15 &amp; ~ledData[i]); <br> <br> // setlatch pin low so the LEDs don't change while sending in bits <br> digitalWrite(latchPin, LOW); <br> // shift out the bits of dataToSend to the 74HC595 <br> shiftOut(dataPin, clockPin, LSBFIRST, dataToSend); <br> //set latch pin high- this sends data to outputs so the LEDs will light up <br> digitalWrite(latchPin, HIGH); <br> <br> } <br>} <br> <br>
//LED TEST 2 w/ 74HC595 <br>//by Amanda Ghassaei 2012 <br>//https://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/ <br> <br>/* <br> * This program is free software; you can redistribute it and/or modify <br> * it under the terms of the GNU General Public License as published by <br> * the Free Software Foundation; either version 2 of the License, or <br> * (at your option) any later version. <br> * <br> * This program is distributed in the hope that it will be useful, <br> * but WITHOUT ANY WARRANTY; without even the implied warranty of <br> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the <br> * GNU General Public License for more details. <br>*/ <br> <br>//this code sends data to the 74HC595 without &quot;shiftOut&quot; <br> <br>//pin connections- the #define tag will replace all instances of &quot;latchPin&quot; in your code with A1 (and so on) <br>#define latchPin A1 <br>#define clockPin A0 <br>#define dataPin A2 <br> <br>//looping variables <br>byte i; <br>byte j; <br> <br>//storage variable <br>byte dataToSend; <br> <br>//storage for led states, 4 bytes <br>byte ledData[] = {1, 3, 7, 15}; <br> <br>void setup() { <br> //set pins as output <br> pinMode(latchPin, OUTPUT); <br> pinMode(clockPin, OUTPUT); <br> pinMode(dataPin, OUTPUT); <br>} <br> <br>void loop() { <br> <br> for (i=0;i&lt;4;i++){ <br> <br> //send data from ledData to each row, one at a time <br> byte dataToSend = (1 &lt;&lt; (i+4)) | (15 &amp; ~ledData[i]); <br> <br> // setlatch pin low so the LEDs don't change while sending in bits <br> digitalWrite(latchPin, LOW); <br> <br>// // shift out the bits of dataToSend to the 74HC595 <br>// shiftOut(dataPin, clockPin, LSBFIRST, dataToSend); <br>// the code below is the equivalent of the two lines above <br> for (j=0;j&lt;8;j++){ <br> digitalWrite(clockPin,LOW); <br> digitalWrite(dataPin,((dataToSend&gt;&gt;j)&amp;1)); <br> digitalWrite(clockPin,HIGH); <br> } <br> <br> <br> //set latch pin high- this sends data to outputs so the LEDs will light up <br> digitalWrite(latchPin, HIGH); <br> <br> } <br>} <br>
arabic letters!!! do u have any idea if is there any software used with arduino to blink led screen????
thanx dear for answer... <br>because i am new to work with arduino... <br>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??? <br>best regards....
what letters do you want to make?
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.
dear sir... <br>u have explained 4*4 led matrix connected to arduino.. <br>but i dont have any idea how to connect 8*8 leds using 74hc595 to arduino???any help plz
same idea, but you need two 74hc595 - one connects to the 8 rows and the other to the eight columns.
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?
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.
Hi It's really Nice Instructables, but can this method to light up up to 120 button simultaneously , thank you very much
yes, definitely.
Great Instructable! <br>One this I am a bit confused about. What is you want to light more than one LED at once. <br>Wouldn't this cause some other lights to illuminate unexpectedly using this method?

About This Instructable




Bio: I'm a grad student at the Center for Bits and Atoms at MIT Media Lab. Before that I worked at Instructables, writing code for ... More »
More by amandaghassaei:OTCA Metapixel - Conway's Game of Life "9 Degrees of Freedom" IMU Twitter Controlled Pet Feeder 
Add instructable to: