{"id":70,"date":"2010-01-08T22:03:23","date_gmt":"2010-01-09T04:03:23","guid":{"rendered":"http:\/\/nootropicdesign.com\/projectlab\/?p=70"},"modified":"2018-11-02T09:40:53","modified_gmt":"2018-11-02T14:40:53","slug":"arduino-police-lights","status":"publish","type":"post","link":"https:\/\/nootropicdesign.com\/projectlab\/2010\/01\/08\/arduino-police-lights\/","title":{"rendered":"Arduino Police Lights"},"content":{"rendered":"<p><strong><em>Difficulty Level = 4<\/em><\/strong>  <a href=\"\/projectlab\/difficulty-levels\/\">[What&#8217;s this?]<\/a><\/p>\n<p>This is an amusing project inspired by flashing blue and red lights on police cars, ambulances, etc. \u00a0This is a perf board Arduino with 5 blue and 5 red LEDs, and the Arduino code lights them up in a pattern similar to police lights.<\/p>\n<p>First, the Arduino built on a perf board. \u00a0It&#8217;s not hard to build your own Arduino. \u00a0I use a real Arduino board to upload code to the ATMega328 chip, then just move it to the project board.<\/p>\n<div id=\"attachment_73\" style=\"width: 650px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2010\/01\/policeLights.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-73\" class=\"size-full wp-image-73\" title=\"policeLights\" src=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2010\/01\/policeLights.jpg\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2010\/01\/policeLights.jpg 640w, https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2010\/01\/policeLights-300x225.jpg 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><p id=\"caption-attachment-73\" class=\"wp-caption-text\">Perfboard Arduino with blue and red LEDs for police lights mini-project<\/p><\/div>\n<p\/>\n<p\/>\nNow here it is in action &#8212; I really think if you don&#8217;t know what you&#8217;re looking at, it looks realistic in the dark.<\/p>\n<p><iframe loading=\"lazy\" width=\"640\" height=\"505\" src=\"https:\/\/www.youtube.com\/embed\/jemgnJVCC-8\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<p>Here&#8217;s the code that makes it work.  Notice that some of the LEDs are controlled using PWM; the second and fourth LED in each of the blue and red groups.  I would invite people to build something similar and tweak this to get the most realistic effect possible!<\/p>\n<pre class=\"codeblockscroll\">\r\n#define NUM_OFF 3\r\n#define DELAY 50\r\n#define PWM_MIN 10\r\n#define PWM_MAX 128\r\n\r\nint blue[5];\r\nint red[5];\r\n\r\nvoid setup()\r\n{\r\n  blue[0] = 19;\r\n  blue[1] = 5;\r\n  blue[2] = 18;\r\n  blue[3] = 6;\r\n  blue[4] = 17;\r\n  red[0] = 13;\r\n  red[1] = 11;\r\n  red[2] = 12;\r\n  red[3] = 10;\r\n  red[4] = 9;\r\n\r\n  for(int i=0;i<5;i++) {\r\n    pinMode(blue[i], OUTPUT);\r\n    pinMode(red[i], OUTPUT);\r\n  }\r\n  randomSeed(analogRead(0));\r\n}\r\n\r\nvoid loop()\r\n{\r\n  allOn();\r\n  analogWrite(blue[1], random(PWM_MIN, PWM_MAX));\r\n  analogWrite(blue[3], random(PWM_MIN, PWM_MAX));\r\n  analogWrite(red[1], random(PWM_MIN, PWM_MAX));\r\n  analogWrite(red[3], random(PWM_MIN, PWM_MAX));\r\n\r\n\r\n  for(int i=0;i&lt;NUM_OFF;i++) {\r\n    digitalWrite(blue[random(5)], LOW);\r\n    digitalWrite(red[random(5)], LOW);\r\n  }\r\n  delay(DELAY);\r\n}\r\n\r\nvoid allOn() {\r\n  for(int i=0;i&lt;5;i++) {\r\n    digitalWrite(blue[i], HIGH);\r\n    digitalWrite(red[i], HIGH);\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Difficulty Level = 4 [What&#8217;s this?] This is an amusing project inspired by flashing blue and red lights on police cars, ambulances, etc. \u00a0This is a perf board Arduino with 5 blue and 5 red LEDs, and the Arduino code lights them up in a pattern similar to police lights. First, the Arduino built on [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[3],"tags":[],"class_list":["post-70","post","type-post","status-publish","format-standard","hentry","category-arduino"],"_links":{"self":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/70","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/comments?post=70"}],"version-history":[{"count":18,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/70\/revisions"}],"predecessor-version":[{"id":1988,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/70\/revisions\/1988"}],"wp:attachment":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/media?parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/categories?post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/tags?post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}