Você está na página 1de 2

Expanding digital output pins on the Arduino using a shift register

Alex Zivanovic March 2009 You may sometimes need more outputs than there are pins on the Arduino. One solution is to use a shift register. There is a good tutorial here http !!""".arduino.cc!en!Tutorial!#hiftOut. You can use an alternative chip$ the %09%$ "hich is sometimes easier to get. &t is availa'le here http !!""".rapidonline.com!(lectronic)*omponents!&ntegrated)*ircuits!+ogic!%000)#eries)*MO#)logic)family!,,0-.! /"!hcf%09% order code .0)0%22$ cost 10.%2 3atasheet http !!""".rapidonline.com!netalogue!specs!.0)0%22.pdf The follo"ing sho"s ho" you can use t"o of them to get -2 outputs using 0 digital pins on the Arduino.

&t uses pins -0$--$-2 on the Arduino$ and the outputs are la'elled 0)-4. *an you see that pin 9 of the lo"er chip is the output data stream that is fed to the input data pin on the upper chip5 6or data to get to the upper chip$ it is shifted through the lo"er chip. This is called daisy)chaining. You can /eep adding chips in this "ay$ still only using three Arduino pins. The program on the next page can 'e used to test this circuit. &t is 'est to attach an +(3 to each output 7"ith an appropriate resistor8 to see "hat is happening.

// program to test using two 4094 shift registers // // if everything is correct, it will light up one LED at a time // int latchPin = 10 int cloc!Pin = 11 int "ataPin = 1# voi" setup$% & pin'o"e$latchPin, ()*P)*% pin'o"e$cloc!Pin, ()*P)*% pin'o"e$"ataPin, ()*P)*% "igital+rite$latchPin, 0% //ma!e sure "ata isn,t latche" voi" loop$% & unsigne" int outputpattern =1 //stores the output pattern as an unsigne" int, that is, two .ytes int pattern/L01 //the least significant .yte $L01% of the pattern int pattern/'01 //the most significant .yte $'01% of the pattern for $int i=0 i2 13 i44%& pattern/'01 = outputpattern 556 //e7tract the '01 of the pattern .y shifting all the .its over .y 6 pattern/L01 = outputpattern 8 111111111 //e7tract the L01 of the pattern .y .itwise 9:D shift(ut$"ataPin, cloc!Pin, '01;<=0*, $.yte% pattern/'01% shift(ut$"ataPin, cloc!Pin, '01;<=0*, $.yte% pattern/L01% "igital+rite$latchPin, 1% // flic! the latch to put the "ata on the output pins "elay$1% "igital+rite$latchPin, 0% "elay$100% outputpattern = outputpattern 221 // shift the outputpattern left .y one .it -

Você também pode gostar