{"id":1613,"date":"2018-04-17T17:54:56","date_gmt":"2018-04-17T21:54:56","guid":{"rendered":"http:\/\/www.circuitcrush.com\/?p=1613"},"modified":"2021-06-30T17:34:26","modified_gmt":"2021-06-30T21:34:26","slug":"control-led-arduino-switches","status":"publish","type":"post","link":"https:\/\/www.circuitcrush.com\/control-led-arduino-switches\/","title":{"rendered":"Video – Use an Arduino & 2 Push Button Switches to Control an LED"},"content":{"rendered":"<p>Greetings fellow geeks, we’re back again with a practical mini-project you can bust out on your bench and use right away. This time I have a short video to go along with the post and also a transcription of the video (scroll down for video) afterwards.<\/p>\n<p>In the video, I use 2 push button switches and an Arduino Uno to turn an LED on and off.<\/p>\n<p>After the video, but before the transcription, you’ll find a schematic and a breadboard circuit diagram (courtesy of Fritzing).<\/p>\n<p>I know, some of you may be thinking <em>who cares, it’s just turning an LED on and off<\/em>…<\/p>\n<p><!--more--><\/p>\n<p>However, this type of circuit can come in handy for controlling many things besides LEDs. Things like motors on robots, LCD displays, relays, and more come to my mind right away.<\/p>\n<p>Plus, if you’re new to Arduino or programming, you may not know how to do this simple exercise. Even if you’re an Arduino\/programming pro, I’m sure you can extend this to other things (which may require extra circuitry).<\/p>\n<p>Take about 4 minutes, watch the video, then leave me a comment and let me know what you’re currently working on and if you’d like to see more videos like this.<\/p>\n<p>This is one of my first videos, so if the picture and\/or audio aren’t quite studio quality I apologize. Improvement is a continuous process and one I usually welcome.<\/p>\n<p>One more thing: be sure to subscribe to my <a href=\"https:\/\/www.youtube.com\/channel\/UC0hZIcHgzKbwFNGTvVruZqg\" target=\"_blank\" rel=\"noopener\">YouTube channel<\/a> as I’ll be making more videos soon.<\/p>\n<h1>How to Use an Arduino & Push Button Switches to Turn an LED on\/off<\/h1>\n<p> <\/p>\n<p><iframe src=\"https:\/\/www.youtube.com\/embed\/GwlNjc293pc?rel=0\" width=\"640\" height=\"385\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><span style=\"display: inline-block; width: 0px; overflow: hidden; line-height: 0;\" data-mce-type=\"bookmark\" class=\"mce_SELRES_start\">\ufeff<\/span><\/iframe><\/p>\n<h2 style=\"text-align: center;\">Become the Maker you were born to be. Try <a href=\"https:\/\/learnarduinonow.com\">Arduino Academy<\/a> for FREE!<\/h2>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-4238\" src=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2.png\" alt=\"\" width=\"431\" height=\"164\" srcset=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2.png 828w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2-300x114.png 300w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2-150x57.png 150w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2-768x292.png 768w\" sizes=\"(max-width: 431px) 100vw, 431px\" \/><\/p>\n<p> <\/p>\n<p> <\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-1616\" src=\"http:\/\/www.circuitcrush.com\/wp-content\/uploads\/Arduino-Push-Button-LED-Circuit-Layout.jpg\" alt=\"Arduino-Push-Button-LED-Circuit-Layout\" width=\"757\" height=\"547\" srcset=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/Arduino-Push-Button-LED-Circuit-Layout.jpg 908w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/Arduino-Push-Button-LED-Circuit-Layout-600x433.jpg 600w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/Arduino-Push-Button-LED-Circuit-Layout-150x108.jpg 150w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/Arduino-Push-Button-LED-Circuit-Layout-300x217.jpg 300w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/Arduino-Push-Button-LED-Circuit-Layout-768x555.jpg 768w\" sizes=\"(max-width: 757px) 100vw, 757px\" \/><\/p>\n<p><em><strong>Figure 1: circuit layout diagram.<\/strong><\/em><\/p>\n<p> <\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-1617\" src=\"http:\/\/www.circuitcrush.com\/wp-content\/uploads\/Arduino-Push-Button-LED-Schematic.jpg\" alt=\"Arduino-Push-Button-LED-Schematic\" width=\"633\" height=\"551\" srcset=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/Arduino-Push-Button-LED-Schematic.jpg 584w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/Arduino-Push-Button-LED-Schematic-150x130.jpg 150w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/Arduino-Push-Button-LED-Schematic-300x261.jpg 300w\" sizes=\"(max-width: 633px) 100vw, 633px\" \/><\/p>\n<p><em><strong>Figure 2: circuit schematic.<\/strong><\/em><\/p>\n<p> <\/p>\n<p><strong><em>Want to get started with Arduino & microcontrollers? You\u2019ll love the new course <a href=\"http:\/\/www.circuitcrush.com\/arduino-get-started-course-access-now-2\/\">How to Get Started With Arduino in 1 Day or Less<\/a>!<\/em><\/strong><\/p>\n<h2><span style=\"text-decoration: underline;\"><strong>Transcription of How to Use Arduino & Push Button Switches to Turn an LED on\/off<br \/>\n<\/strong><\/span><\/h2>\n<p><em>Note: I did not transcribe this myself. Please excuse any spelling, grammar, punctuation errors or omissions.<\/em><\/p>\n<p>Hello and welcome to circuit crush TV.<\/p>\n<p>Today I want to show you guys how to turn a LED on and off with an Arduino Uno and a couple of push button switches.\u00a0 Now, this is pretty-simple and some of you may be thinking well who cares it\u2019s just a LED.\u00a0 There are a ton of other uses for a set up like this.\u00a0 So, let\u2019s say you have a robot that you have a couple of bumper switches on and when the switch hits you want it to change directions.\u00a0 This\u2019ll come in handy for that kind of application and a lot of other things.\u00a0 So, don\u2019t think that this is just limited to blinking a LED or turning the LED on and off rather with a push of a button.\u00a0 You can use this to turn anything on and off whether it\u2019s a motor, a fan, an LCD display, it\u2019s just pretty much limitless to what you can do with this kind of circuit.<\/p>\n<p>Now I already wired it up, and I want to quickly go over these circuits.\u00a0 You notice there is two push buttons, here and here and this third one off to the side.\u00a0 I have that there because the orientation of the switches is pretty important.\u00a0 There are four pins, and some of them are connected internally.\u00a0 So, if you don\u2019t put them in the breadboard in the right orientation it won\u2019t work.\u00a0 And you see we have a little gap here, and I made sure that there are two legs on one side and two on the other.\u00a0 Now you might be wondering which two legs are connected and which are not.\u00a0 To figure that out I grab my Ohm meter here and we can see that those two are connected and these two are not unless I push the button then it connects.\u00a0 That\u2019s the right way to orient these push button switches.<\/p>\n<p>Really quickly we have, of course one ground wire here right to the Arduino ground pin and we have these three blue jumper wires.\u00a0 They are grounds for the push button switches and the cathode of this LED will be at ground.\u00a0 And then we have a 150 Ohm resistor on the anode.\u00a0 That value really isn\u2019t critical anything from 120-220, 250 depending on how bright you want it, should work. But you want to have some resistor, at least 100.\u00a0 I wouldn\u2019t go any less than that.\u00a0 And then we have that LED connected to pin 5 or digital pin 5.<\/p>\n<p>Also, we have one the switches with this yellow jumper going to pin 9 and this blue jumper here on the other switch going to pin 8. So, I already wired this thing up and I already written a simple program to make this thing work.\u00a0 I\u2019m going to demonstrate it and then we\u2019ll get into the program a little bit here.\u00a0 So, let me plug in the Arduino here, and the code should be uploaded, let\u2019s see.\u00a0 Okay so on and the other button off, on, off.\u00a0 Pretty simple stuff.<\/p>\n<p>So, let\u2019s cut on over and take a quick look at this code, it\u2019s real simple.<\/p>\n<p>Okay so here we can see the simple program on my computer screen here that makes this thing tick.\u00a0 All we\u2019re doing is initiating a couple of pins as you can see up top.\u00a0 We are designating the pins as output one of them and then the other two are input pullups, and then we just go into the loop.\u00a0 It\u2019s just saying, look, if one button is pressed, if this button is pressed make this pin high.\u00a0 If the other button is pressed, make the other pin low, which turns the LED on and off.\u00a0 So, this is real simple stuff guys.<\/p>\n<p>I know it\u2019s a short video, hopefully you enjoyed it.\u00a0 Go ahead and leave me a comment and let me know what you think and let me know what you guys are working on.<\/p>\n<h2 style=\"text-align: center;\">Become the Maker you were born to be. Try <a href=\"https:\/\/learnarduinonow.com\">Arduino Academy<\/a> for FREE!<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4238\" src=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2.png\" alt=\"\" width=\"828\" height=\"315\" srcset=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2.png 828w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2-300x114.png 300w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2-150x57.png 150w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2-768x292.png 768w\" sizes=\"(max-width: 828px) 100vw, 828px\" \/><\/p>\n<a target=\"_blank\" href=\"https:\/\/www.drpeterscode.com\/index.php\"><img src=\"https:\/\/www.circuitcrush.com\/wp-content\/plugins\/dpabottomofpostpage\/apixel1x1.jpg\" ><\/a><table><\/table>","protected":false},"excerpt":{"rendered":"<p>Greetings fellow geeks, we’re back again with a practical mini-project you can bust out on your bench and use right away. This time I have a short video to go along with the post and also a transcription of the video (scroll down for video) afterwards. In the video, I use 2 push button switches […]<\/p>\n","protected":false},"author":1,"featured_media":1620,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[32,10],"tags":[34,24,33],"class_list":{"0":"post-1613","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-arduino","8":"category-getting-started","9":"tag-arduino","10":"tag-getting-started-in-electronics","11":"tag-microcontrollers","12":"entry"},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/Arduino-Push-Button-Control.jpg","_links":{"self":[{"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/posts\/1613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/comments?post=1613"}],"version-history":[{"count":3,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/posts\/1613\/revisions"}],"predecessor-version":[{"id":4303,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/posts\/1613\/revisions\/4303"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/media\/1620"}],"wp:attachment":[{"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/media?parent=1613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/categories?post=1613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/tags?post=1613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}