{"id":1578,"date":"2016-02-04T12:19:42","date_gmt":"2016-02-04T10:19:42","guid":{"rendered":"https:\/\/blog.zitnik.si\/?p=1578"},"modified":"2018-06-27T18:24:28","modified_gmt":"2018-06-27T16:24:28","slug":"part-13-controlling-leds-using-raspberry-pi","status":"publish","type":"post","link":"https:\/\/blog.zitnik.si\/?p=1578","title":{"rendered":"Part 1\/3: Controlling LEDs using Raspberry Pi"},"content":{"rendered":"<p>In this post I will review, how to turn on or off LEDs using Raspberry Pi 2, Model B (RPi).<\/p>\n<p>First we copy Raspbian linux to a microSD card, turn on RPi and connect to it using ssh.<\/p>\n<p>We use three LEDs and each needs to be connected to each own positive supply of the circuit and ground, as well as, we needed <a href=\"https:\/\/gflaser.co.uk\/\">laser cutting<\/a> to get the perfect size. For the positive supply\u00a0on RPi we use pins 18, 17 and 27 as seen on the scheme below:<\/p>\n<p><a href=\"https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/RPi_GPIO.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1579 size-full\" src=\"https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/RPi_GPIO.png\" alt=\"RPi_GPIO\" width=\"219\" height=\"545\" srcset=\"https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/RPi_GPIO.png 219w, https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/RPi_GPIO-121x300.png 121w\" sizes=\"auto, (max-width: 219px) 100vw, 219px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>As the current would be too high if we connect the LED directly into the circuit, we need to add a resistor for each LED. As it is written in the Raspberry Pi spec, it can safely allow up to 16mA current. Our pins can supply 3.3V. Therefore to allow the LED to be the brightest, we can use 210Ohm \u00a0or stronger resistor. Using stronger resistor will result in the LED not being so bright.<\/p>\n<p>In this example I am using 560Ohm resistor. I am also attaching a nice scheme for calculating the resistance of 4-band resistors:<\/p>\n<p><a href=\"https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/Screen-Shot-2016-02-04-at-11.09.35.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1580 size-full\" src=\"https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/Screen-Shot-2016-02-04-at-11.09.35.png\" alt=\"Screen Shot 2016-02-04 at 11.09.35\" width=\"442\" height=\"504\" srcset=\"https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/Screen-Shot-2016-02-04-at-11.09.35.png 442w, https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/Screen-Shot-2016-02-04-at-11.09.35-263x300.png 263w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>To control a specific LED, we can &#8220;turn on&#8221; a specific LED using a Python library. First we need to set a pin as output and then we can turn it on (GPIO.HIGH) or off (GPIO.LOW). An example of a script that turns on a LED:<\/p>\n<p>[codesyntax lang=&#8221;python&#8221;]<\/p>\n<pre>import RPi.GPIO as GPIO\r\nimport time\r\nGPIO.setmode(GPIO.BCM)\r\nGPIO.setwarnings(False)\r\n\r\nGPIO.setup(18,GPIO.OUT)\r\nGPIO.output(18,GPIO.HIGH)<\/pre>\n<p>[\/codesyntax]<\/p>\n<p>Physical result:<\/p>\n<p><a href=\"https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/IMG_0161.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1581 size-medium\" src=\"https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/IMG_0161-300x225.jpg\" alt=\"IMG_0161\" width=\"300\" height=\"225\" srcset=\"https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/IMG_0161-300x225.jpg 300w, https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/IMG_0161-768x576.jpg 768w, https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/IMG_0161-1024x768.jpg 1024w, https:\/\/blog.zitnik.si\/wp-content\/uploads\/2016\/02\/IMG_0161.jpg 1200w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<div style=\"margin-top: 0px; margin-bottom: 0px;\" class=\"sharethis-inline-share-buttons\" ><\/div>","protected":false},"excerpt":{"rendered":"<p>In this post I will review, how to turn on or off LEDs using Raspberry Pi 2, Model B (RPi). First we copy Raspbian linux to a microSD card, turn on RPi and connect to it using ssh. We use three LEDs and each needs to be connected to each&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/blog.zitnik.si\/?p=1578\">Continue reading<span class=\"screen-reader-text\">Part 1\/3: Controlling LEDs using Raspberry Pi<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":1581,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,30],"tags":[],"class_list":["post-1578","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-computer-engineering","category-free-time","entry"],"_links":{"self":[{"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/posts\/1578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1578"}],"version-history":[{"count":5,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/posts\/1578\/revisions"}],"predecessor-version":[{"id":1672,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/posts\/1578\/revisions\/1672"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=\/wp\/v2\/media\/1581"}],"wp:attachment":[{"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zitnik.si\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}