{"id":219,"date":"2014-03-25T12:48:23","date_gmt":"2014-03-25T12:48:23","guid":{"rendered":"http:\/\/4tronix.co.uk\/blog\/?p=219"},"modified":"2014-03-25T12:52:28","modified_gmt":"2014-03-25T12:52:28","slug":"simple-raspberry-pi-traffic-lights","status":"publish","type":"post","link":"https:\/\/4tronix.co.uk\/blog\/?p=219","title":{"rendered":"Simple Raspberry Pi Traffic Lights"},"content":{"rendered":"<h2>Using Breadboard, LED &amp; Resistors to Create a Traffic Light<\/h2>\n<p><strong>Click on any image to enlarge<\/strong><\/p>\n<h3>Fritzing Diagram<\/h3>\n<p><a href=\"http:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/tl04.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-220\" alt=\"tl04\" src=\"http:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/tl04-265x300.jpg\" width=\"265\" height=\"300\" srcset=\"https:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/tl04-265x300.jpg 265w, https:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/tl04.jpg 740w\" sizes=\"auto, (max-width: 265px) 100vw, 265px\" \/><\/a><\/p>\n<h3>PiCard:<\/h3>\n<p><a href=\"http:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/picard02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-221\" alt=\"picard02\" src=\"http:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/picard02-221x300.jpg\" width=\"221\" height=\"300\" srcset=\"https:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/picard02-221x300.jpg 221w, https:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/picard02.jpg 328w\" sizes=\"auto, (max-width: 221px) 100vw, 221px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Assembling Hardware<\/h3>\n<p>Pop the PiCard pinout display over the GPIO pins on your Raspberry Pi \u00ae making sure that pin 2 is in the corner of the board. This allows you to easily see where to plug the wires.<\/p>\n<p>Push the LEDs and resistors (cut the legs shorter on the resistors first) into the breadboard as shown. LEDs have a positive and a negative leg. Positive leg on the right above is longer. Make sure you plug them in the correct way round or they will not work.<\/p>\n<ul>\n<li>Connect resistor on Red LED to pin 7<\/li>\n<li>Connect resistor on Amber LED to pin 11<\/li>\n<li>Connect resistor on Green LED to pin 13<\/li>\n<li>Connect negative leg of Red LED to pin 6<\/li>\n<li>Connect negative leg of Amber LED to pin 14<\/li>\n<li>Connect negative leg of Green LED to pin20<\/li>\n<li>Connect one side of switch to pin 22<\/li>\n<li>Connect other side of switch to pin 25<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3>Completed Traffic Lights<\/h3>\n<p><a href=\"http:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/tl03b.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-222\" alt=\"tl03b\" src=\"http:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/tl03b-300x209.jpg\" width=\"300\" height=\"209\" srcset=\"https:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/tl03b-300x209.jpg 300w, https:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/tl03b.jpg 800w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Programming<\/h3>\n<p>To light the LEDs you need to make the corresponding GPIO pin High. Make the pin low to turn off the light.<\/p>\n<ul>\n<li>Red is on <strong>pin 7<\/strong><\/li>\n<li>Amber is on <strong>pin 11<\/strong><\/li>\n<li>Green is on <strong>pin 13<\/strong><\/li>\n<\/ul>\n<p>To read the switch you need to read on <strong>pin 22<\/strong>. A High value (&#8216;1&#8217;) when the switch is up (not pressed) and a Low value (&#8216;0&#8217;) when the switch is pressed.<\/p>\n<p>&nbsp;<\/p>\n<h3>Python Examples<\/h3>\n<p>Download the example code <a href=\"http:\/\/www.4tronix.co.uk\/rpi\/TrafficKit01.py\">from here <\/a>and place it in your home directory on the Raspberry Pi.Then you can run it by typing:<\/p>\n<p><em>sudo python TrafficKit01.py<\/em><\/p>\n<p>This will light the LEDs in the well know traffic light sequence. Now try to edit the code to make it do something different.<\/p>\n<p>You can download the second demo example <a href=\"http:\/\/www.4tronix.co.uk\/rpi\/TrafficKit02.py\">from here<\/a> and run it with:<\/p>\n<p><em>sudo python TrafficKit02.py<\/em><\/p>\n<p>This will light the LEDs in sequence but will also check the button occasionally and force it to the Red if the button is pressed<\/p>\n<p>&nbsp;<\/p>\n<h3>ScratchGPIO Examples<\/h3>\n<p>You will need to first install ScratchGPIO if you haven&#8217;t already. Go to <a href=\"http:\/\/cymplecy.wordpress.com\/scratchgpio\/\">SimpleSi&#8217;s page<\/a><\/p>\n<p>Within ScratchGPIO you can switch the Red LED on with <img decoding=\"async\" alt=\"\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJEAAAAkCAIAAAAGvU+yAAAB2ElEQVRoge2avW3DMBCFvUI61QYyQRZIlwUygwHDZSAggGMggYdIrc4LZISk8R6uXaajCwG0IpKPZ4r6OeURr3imxKN4n46CAS7K1+3b+3613uw+9vQq\/GIiz0FPZnP2ZKbPk5k+H2Rmvp9Cks8BglByiZj9ft0DyZnhOJRcEWb1TafDEkjCDEegblVXZqfDEjMbfYW1Xp7vtMuupSqLrszwFjw6Lcvs5\/NBr87H69ufgZkK9cTMGDPAkHRmxhhjTE857TW4kBnOpvnbwJBoHDITBclbZ5gZ66wXZm7FtEi4V71Jx3G8N4SCP\/paHma2tdLkdrYyGO0EwyUBvaEAM1A0IQD4qjAOCB4ClqfOQKa8t3mrAQSMVhKOLKmzNGbgZ3dmTWz590aQuxAzIV0Awx3b7JkHsxqb2zkCs7RO\/BJIrgJmtsnT6qZYMrw1UZSZV718z0JlIRkOOiV15p1aXmfDqOOM\/E89HDO3mskskZk6kZk+\/VNm5+NWtUTMVuvN6LmmWqrKIn62YPSnpKyqspCe4anKwqubJqO6K8O5KyE2u\/9O4azSnDyZ6fOJ5xuj2JrfzCmsc04+\/Uwq3oKnsLa5ep4j1ufJTJ8nM32ezPR5MtPnyUyfvwCUUrfVq2\/3BwAAAABJRU5ErkJggg==\" \/><\/p>\n<p>Switch it off again with <img decoding=\"async\" alt=\"\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIkAAAAiCAIAAADknW2zAAABu0lEQVRoge2aPW6DQBCFfQV31JFyglwgXS7gMyAhSgspkh3JEYdITZcL5AhJ43ukdpluU1giZH\/eDmaBQbzVk\/U8sAOej1lkm01elC+vdfV8OJ5qelV+o+Q86MlmSZ5s9Hqy0es9bMznU0jyvCAJJaytzebn4x5IzgbnobxCbK57fL\/fAUnY4AwU0CA21nzXz\/7xrtrvtgtSe9pNlQ1ig9fN2am0bL7eHhahy\/nvgh7KZhEaiY0xRgUbY4wxZqTajZpcyAYX2vwfZJMsSdq+IZsR2bgdYFXc3eptL8uHElr+0TcSsGmHVQ43aFUqGgTTJQm9qQAb0AShmkrmusHuawhPyr4BFfHu5r26QcJoZ+DMkr65jU3obV82XTyJ1zRQoxAbIUVQdHduN6KQDQDT4nGDU7O5LYhhS7YCNu3oW2jA2EoYZeNV+vtN6DKXTAdBSd94Dy3vG21a+3dPslEk\/majV2SjV\/vd9nI+LEVxNnlRzl7TNaupssh\/0rOf4jrVVJnoWY6myrzqdSSql4Y+ZyPEY\/Um\/RTPQJGNXjbHUx3F466b9BOxyYuy77pJPx0berJZuycbvZ5s9PpfCOReOvkbVYUAAAAASUVORK5CYII=\" \/><\/p>\n<p>Similarly you can use the other pins for the Yellow and Green LEDs. A complete Traffic Light Sequence is shown here:<\/p>\n<p><a href=\"http:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/traffic.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-227\" alt=\"traffic\" src=\"http:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/traffic-149x300.jpg\" width=\"149\" height=\"300\" srcset=\"https:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/traffic-149x300.jpg 149w, https:\/\/4tronix.co.uk\/blog\/wp-content\/uploads\/2014\/03\/traffic.jpg 385w\" sizes=\"auto, (max-width: 149px) 100vw, 149px\" \/><\/a><\/p>\n<p>You can download this <a href=\"http:\/\/www.4tronix.co.uk\/rpi\/Traffic01.sb\">from here<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Breadboard, LED &amp; Resistors to Create a Traffic Light Click on any image to enlarge Fritzing Diagram PiCard: &nbsp; Assembling Hardware Pop the PiCard pinout display over the GPIO pins on your Raspberry Pi \u00ae making sure that pin 2 is in the corner of the board. This allows you to easily see where &hellip; <a href=\"https:\/\/4tronix.co.uk\/blog\/?p=219\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Simple Raspberry Pi Traffic Lights<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-219","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi-addons"],"_links":{"self":[{"href":"https:\/\/4tronix.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/4tronix.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/4tronix.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/4tronix.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/4tronix.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=219"}],"version-history":[{"count":5,"href":"https:\/\/4tronix.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/219\/revisions"}],"predecessor-version":[{"id":229,"href":"https:\/\/4tronix.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/219\/revisions\/229"}],"wp:attachment":[{"href":"https:\/\/4tronix.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/4tronix.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/4tronix.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}