{"id":292,"date":"2015-02-08T17:07:19","date_gmt":"2015-02-09T01:07:19","guid":{"rendered":"http:\/\/www.antunkarlovac.com\/blog\/?p=292"},"modified":"2022-09-12T09:31:29","modified_gmt":"2022-09-12T17:31:29","slug":"arduino-stopwatch-experiment","status":"publish","type":"post","link":"https:\/\/www.antunkarlovac.com\/blog\/2015\/02\/08\/arduino-stopwatch-experiment\/","title":{"rendered":"Arduino Stopwatch Experiment"},"content":{"rendered":"<p>I&#8217;ve been working my way through the lessons\u00a0in the\u00a0<a href=\"http:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;index=aps&amp;keywords=B00HEBHWWW&amp;linkCode=ur2&amp;tag=antukarl-20&amp;linkId=2XKWJUVGITBVHZF7\">SunFounder LCD Ultrasonic Relay Sensor Electronic Bricks Starter Kit<\/a>. The kit comes with a manual, and the early experiments have pretty detailed steps with electronics diagrams.<br \/>\n<a href=\"http:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;index=aps&amp;keywords=B00HEBHWWW&amp;linkCode=as2&amp;tag=antukarl-20&amp;linkId=MSBVIIHUVFFDD2JW\"><img decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/ws-na.amazon-adsystem.com\/widgets\/q?_encoding=UTF8&amp;ASIN=B00HEBHWWW&amp;Format=_SL160_&amp;ID=AsinImage&amp;MarketPlace=US&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=antukarl-20\" alt=\"\" border=\"0\" \/><\/a><img decoding=\"async\" loading=\"lazy\" style=\"border: none !important; margin: 0px !important;\" src=\"http:\/\/ir-na.amazon-adsystem.com\/e\/ir?t=antukarl-20&amp;l=as2&amp;o=1\" alt=\"\" width=\"1\" height=\"1\" border=\"0\" \/><\/p>\n<p>But by the time you get to the stopwatch experiment (lesson 13) there are no more diagrams, so I was left to figure out how to connect the 4-digit 7-segment display. My display had the part number SMA420564, and it had 12 pins. I couldn&#8217;t find a spec sheet for it, to understand which pins referred to which segment\/digit. After a bit of trial and error, I figured it out:<\/p>\n<figure id=\"attachment_293\" aria-describedby=\"caption-attachment-293\" style=\"width: 454px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/pin_diagram_SMA420564.png\"><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-293\" src=\"http:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/pin_diagram_SMA420564.png\" alt=\"Pin Diagram for SMA420564\" width=\"454\" height=\"299\" srcset=\"https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/pin_diagram_SMA420564.png 583w, https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/pin_diagram_SMA420564-300x197.png 300w\" sizes=\"(max-width: 454px) 100vw, 454px\" \/><\/a><figcaption id=\"caption-attachment-293\" class=\"wp-caption-text\">Pin Diagram for SMA420564<\/figcaption><\/figure>\n<p>The way I figured it out which pin mapped to which was to adapt the example program that came with the kit to light all segments at once (i.e. &#8220;8.&#8221;) and then plug\/unplug wires until I figured out which was which. I don&#8217;t really know the pin numbers, but as long as you know which digit\/segment they light, that&#8217;s enough. The pins\u00a0d1, d2, d3, and d4 correspond with each digit, with d1 being the first on the left. The pins with capital letters correspond with the segments A-G of the 7-segment character. The naming convention appears to be quite standardized. The diagram below shows which letter corresponds with which segment:<\/p>\n<p><a href=\"http:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/7-segment-display-labeled.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter  wp-image-298\" src=\"http:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/7-segment-display-labeled.png\" alt=\"7-segment-display-labeled\" width=\"205\" height=\"245\" srcset=\"https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/7-segment-display-labeled.png 304w, https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/7-segment-display-labeled-250x300.png 250w\" sizes=\"(max-width: 205px) 100vw, 205px\" \/><\/a><\/p>\n<p>Here&#8217;s a wiring schematic to show which pins of the Arduino each pin goes to. Note that in the diagram below, the LED display is rotated 90\u00ba clockwise:<\/p>\n<figure id=\"attachment_294\" aria-describedby=\"caption-attachment-294\" style=\"width: 490px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/Timer_Schematic.png\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-294\" src=\"http:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/Timer_Schematic.png\" alt=\"Timer_Schematic\" width=\"490\" height=\"216\" srcset=\"https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/Timer_Schematic.png 1046w, https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/Timer_Schematic-300x132.png 300w, https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/Timer_Schematic-1024x451.png 1024w\" sizes=\"(max-width: 490px) 100vw, 490px\" \/><\/a><figcaption id=\"caption-attachment-294\" class=\"wp-caption-text\">Schematic for Experiment 13 in Sunfounder Ultrasonic Kit for Arduino<\/figcaption><\/figure>\n<p>I used Upverter to create the diagram, and you can access it <a href=\"https:\/\/upverter.com\/antun\/d6062dd7810fb654\/Timer\/\">directly on the Upverter site<\/a>.<\/p>\n<p>With everything wired, it was time to try the code. The kit I had came with one of those small CDs, so I actually downloaded it from the Sunfounder web site. It&#8217;s <a href=\"http:\/\/www.sunfounder.com\/index.php?c=downloads\">lesson #13 in the Ultrasonic Kit for Arduino here.<\/a>\u00a0(NOTE: The original URL doesn&#8217;t work, but I found a ZIP of the <a href=\"https:\/\/www.adrive.com\/public\/GrVVx3\/Ultrasonic%20Kit.zip\">entire set of lessons for the Ultrasonic Kit<\/a>, and also posted the <a href=\"https:\/\/gist.github.com\/antun\/3ca3b446f91d5b2e5b60ef5a6f65c777\">source for lesson #13 as a Gist<\/a>.) When I tried to validate the stopwatch, it failed with the following error:<\/p>\n<blockquote><p>Timer1 was not declared in this scope<\/p><\/blockquote>\n<p>Turns out that there are some C++ libraries that the Sunfounder example code relies on, which weren&#8217;t in my environment. I found this blog post that talks about the error, and there&#8217;s a link to download the TimerOne library. After downloading it I wasn&#8217;t really sure what to do with the .h and .cpp files. I tried placing them in the same directory as my .ino file, but that didn&#8217;t help. Eventually I figured out that you have to import it via the Arduino IDE (Sketch&gt;Import Library&gt;Add Library&#8230; and then select the folder that contains the TimerOne.cpp and TimerOne.h files.<\/p>\n<p>With that done, I was able to burn the program to my Arduino, and now have a happy stopwatch:<\/p>\n<p><a href=\"http:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/stopwatch.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-295\" src=\"http:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/stopwatch.png\" alt=\"stopwatch\" width=\"490\" height=\"298\" srcset=\"https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/stopwatch.png 690w, https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2015\/02\/stopwatch-300x182.png 300w\" sizes=\"(max-width: 490px) 100vw, 490px\" \/><\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been working my way through the lessons\u00a0in the\u00a0SunFounder LCD Ultrasonic Relay Sensor Electronic Bricks Starter Kit. The kit comes with a manual, and the early experiments have pretty detailed steps with electronics diagrams. But by the time you get to the stopwatch experiment (lesson 13) there are no more diagrams, so I was left &hellip; <a href=\"https:\/\/www.antunkarlovac.com\/blog\/2015\/02\/08\/arduino-stopwatch-experiment\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Arduino Stopwatch Experiment<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,12],"tags":[],"_links":{"self":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/292"}],"collection":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/comments?post=292"}],"version-history":[{"count":3,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/292\/revisions"}],"predecessor-version":[{"id":416,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/292\/revisions\/416"}],"wp:attachment":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/media?parent=292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/categories?post=292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/tags?post=292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}