{"id":1275,"date":"2014-06-05T21:28:02","date_gmt":"2014-06-05T19:28:02","guid":{"rendered":"http:\/\/labalec.fr\/erwan\/?p=1275"},"modified":"2014-06-08T15:20:42","modified_gmt":"2014-06-08T13:20:42","slug":"arduino-use-a-shift-register","status":"publish","type":"post","link":"https:\/\/labalec.fr\/erwan\/?p=1275","title":{"rendered":"Arduino : use a shift register (74HC595)"},"content":{"rendered":"<p>I have a <a href=\"https:\/\/www.google.fr\/search?q=wordclock&amp;safe=off&amp;source=lnms&amp;tbm=isch&amp;sa=X&amp;ei=YsmQU4gBpPPSBaX6gLAG&amp;ved=0CAYQ_AUoAQ&amp;biw=1920&amp;bih=912\" target=\"_blank\">wordclock project<\/a>.<\/p>\n<p>Before I get there, I need to learn about transistors (see<a href=\"https:\/\/labalec.fr\/erwan\/?p=1263\" target=\"_blank\"> previous article<\/a>) to handle an external power source for my leds and a shift register to control lots of leds with an Arduino.<\/p>\n<p>Why am I not using the digital pins?<br \/>\nFor 2 reasons :<br \/>\n-the digital pins are there to input\/output a logic (0\/1), not power<br \/>\n-my arduino only has 14 digital pins (I need about 25 output)<\/p>\n<p>So to sum it up, we will use<br \/>\n-an external power source to power on our leds,<br \/>\n-transistors to isolate the external power source from the arduino,<br \/>\n-a shift register (<a href=\"http:\/\/www.nxp.com\/documents\/data_sheet\/74HC_HCT595.pdf\" target=\"_blank\">74HC595<\/a>) to handle 8 outputs at once with only 3 pins.<\/p>\n<p>See below a wiring to use shift registers on two leds (it would be more impressive\/significant with 8 leds with I was too lazy to draw it all).<br \/>\nNotice that we also use our external power source to power on the Arduino thru the vin pin.<\/p>\n<p>About transistors, next evolution is to replace the serie of transistors by a transistor array like a uln2803a.<\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/06\/74HC595_3_bb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1280 size-large\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/06\/74HC595_3_bb-1024x783.png\" alt=\"74HC595_3_bb\" width=\"695\" height=\"531\" srcset=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/06\/74HC595_3_bb-1024x783.png 1024w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/06\/74HC595_3_bb-300x229.png 300w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/06\/74HC595_3_bb.png 1905w\" sizes=\"auto, (max-width: 695px) 100vw, 695px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>And now the arduino sketch.<\/p>\n<p>note : all led on =b11111111 (255), 7 led on =b0111111, 6 led on=b00111111, etc &#8230;<\/p>\n<pre>\/\/the pins we are using\r\nint latchPin = 2;\r\nint clockPin = 3;\r\nint dataPin = 4;\r\n \r\nvoid setup() {\r\n  \/\/set all the pins used to talk to the chip\r\n  \/\/as output pins so we can write to them\r\n  pinMode(latchPin, OUTPUT);\r\n  pinMode(clockPin, OUTPUT);\r\n  pinMode(dataPin, OUTPUT);\r\n}\r\n \r\nvoid loop() {\r\n  for (int i = 0; i < 8; i++) {\r\n \r\n    \/\/take the latchPin low so the LEDs don't change while we are writing data\r\n    digitalWrite(latchPin, LOW);\r\n \r\n    \/\/shift out the bits\r\n    shiftOut(dataPin, clockPin, MSBFIRST, i);  \r\n \r\n    \/\/take the latch pin high so the pins reflect\r\n    \/\/the data we have sent\r\n    digitalWrite(latchPin, HIGH);\r\n\r\n    \/\/ pause before next value:\r\n    delay(1000);\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have a wordclock project. Before I get there, I need to learn about transistors (see previous article) to handle an external power source for my leds and a shift register to control lots of leds with an Arduino. Why am I not using the digital pins? For 2 reasons : -the digital pins are <a href='https:\/\/labalec.fr\/erwan\/?p=1275' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[51],"class_list":["post-1275","post","type-post","status-publish","format-standard","hentry","category-arduino","tag-74hc595","category-18-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/1275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1275"}],"version-history":[{"count":12,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/1275\/revisions"}],"predecessor-version":[{"id":1304,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/1275\/revisions\/1304"}],"wp:attachment":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}