{"id":105,"date":"2024-10-14T20:02:20","date_gmt":"2024-10-15T00:02:20","guid":{"rendered":"https:\/\/wp.stgeorges.bc.ca\/timd\/?p=105"},"modified":"2024-10-14T20:09:53","modified_gmt":"2024-10-15T00:09:53","slug":"assignment-2-robotics","status":"publish","type":"post","link":"https:\/\/wp.stgeorges.bc.ca\/timd\/2024\/10\/14\/assignment-2-robotics\/","title":{"rendered":"Assignment #2 \u2013 Robotics"},"content":{"rendered":"\n<p>This is my second mini-assignment out of the 3 Fusion self-paced assignments. My previous post documents my project on CAD, where I made a 3D model of a birdhouse with mechanical drawings and a BOM.<\/p>\n\n\n\n<p><strong>For this particular robotics assignment, I must demonstrate my understanding of these skills through this blog post:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Circuit Building &#8211; planning and building a circuit that allows an Arduino board to interact with other components<\/li>\n\n\n\n<li>Arduino Programming &#8211; writing code that will make your device do something<\/li>\n<\/ol>\n\n\n\n<p>I was provided with an Arduino Starter Kit, and I decided to create a simple keyboard that plays a full octave of notes.<\/p>\n\n\n\n<p>\u00b7<\/p>\n\n\n\n<p><strong>You can try out my keyboard and see the complete code through this link:<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.tinkercad.com\/things\/8TMxggLNMvF-fusion-keyboard?sharecode=KBWNH_ZxQxGI-m2fHT0WW5OOII0kOKbRL0KlXHBXUVo\">https:\/\/www.tinkercad.com\/things\/8TMxggLNMvF-fusion-keyboard?sharecode=KBWNH_ZxQxGI-m2fHT0WW5OOII0kOKbRL0KlXHBXUVo<\/a><\/p>\n\n\n\n<p>\u00b7<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Skill 1: Circuit Building<\/h2>\n\n\n\n<p>The first step of my project was building the physical circuit. For me, this was the most straightforward part of the process.<\/p>\n\n\n\n<p>I decided to use push buttons as the keys of the keyboard and also add LEDs connected to each button that would light up when a key was pressed. I also planned to have a single wire connected to the ground pin, 8 other wires for each of the buttons (one for each note of the octave), 8 resistors (one for each button), and one last wire for the buzzer.<\/p>\n\n\n\n<p>After assembling my circuits, I noticed two interesting things.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. <strong>Different coloured LEDs need different amounts of electricity<\/strong><\/h4>\n\n\n\n<p>When testing the first draft of my keyboard, I noticed that some buttons weren&#8217;t working. I originally suspected something was wrong with my code, but eventually decided that couldn&#8217;t have been the case since the code for my other buttons was written the same way, and they worked properly. So, I determined it had to be a hardware issue. I later noticed that all the malfunctioning buttons were connected to blue LEDs. After replacing all the blue LEDs with differently colored ones, the buttons started working. Because of this, I came to the conclusion that blue LEDs consumed much more electricity than other LEDs.<\/p>\n\n\n\n<p>Later, I noticed that my working LEDs glowed at largely different brightnesses. In fact, the green ones barely turned on. This further confirmed my previous conclusion. This is the ranking I discovered based on how much electricity each color of LEDs uses: <strong>Blue &gt; Green &gt; Yellow &gt; Red.<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. <strong>Resistors aren&#8217;t needed for this circuit<\/strong><\/h4>\n\n\n\n<p>The first iterations of my keyboard had resistors for every button, but those seemed to cause my entire keyboard to stop functioning. Previously, I had thought that push buttons didn&#8217;t consume any electricity themselves and that directly connecting a button with an LED to the Arduino would burn the LED out. Through my experimentation, it seems that buttons do require energy and act as a resistor themselves, so I ended up just removing all my previous resistors.<\/p>\n\n\n\n<p>\u200e\u200e\u200e\u200e\u200e\u200e\u200e\u200e\u200e\u200e\u00b7<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-content\/uploads\/sites\/10\/2024\/10\/20241014_142819-Large-1024x768.jpeg\" alt=\"\" class=\"wp-image-109\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-content\/uploads\/sites\/10\/2024\/10\/20241014_142819-Large-1024x768.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/timd\/wp-content\/uploads\/sites\/10\/2024\/10\/20241014_142819-Large-300x225.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/timd\/wp-content\/uploads\/sites\/10\/2024\/10\/20241014_142819-Large-768x576.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/timd\/wp-content\/uploads\/sites\/10\/2024\/10\/20241014_142819-Large.jpeg 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Photo of my completed circuit<\/figcaption><\/figure>\n\n\n\n<p>\u00b7<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Skill 2: Arduino Programming<\/h2>\n\n\n\n<p>Programming was the most time-consuming and the most difficult part of this project for me. I used various online tutorials and tried to stick to simple code I already knew how to use.<\/p>\n\n\n\n<p>There were many new things and techniques I learned, but here are a few I found to be the most useful and that you should know about.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>int<\/strong>\n<ul class=\"wp-block-list\">\n<li><code>int<\/code> is short for <strong>integer<\/strong>. It is a basic data type (a piece of data that tells a computer system how to understand a value) in programming that represents a whole number, positive or negative, without any decimal point.<\/li>\n\n\n\n<li>For example: \n<ul class=\"wp-block-list\">\n<li>int buttonPin = 2; means the variable &#8216;buttonPin&#8217; is assigned the number 2 (the pin number on the Arduino).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>In Arduino, an int can store values from -32,768 to 32,767, which is almost always enough for things like pin numbers or simple counters. It basically helps keep things organized and assigns a number to everything.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>float<\/strong>\n<ul class=\"wp-block-list\">\n<li><strong>float<\/strong> is a data type in programming that stands for &#8220;floating-point.&#8221; It represents numbers that can have decimal points, allowing for more precise values than integers. It&#8217;s basically a more specific version of <strong>int.<\/strong><\/li>\n\n\n\n<li>For example:\n<ul class=\"wp-block-list\">\n<li>float frequency = 261.63 means the variable &#8216;frequency&#8217; holds the number 261.63, which could represent the frequency of a musical note.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>In Arduino, a float can store a wide range of values and is useful for calculations involving measurements or decimals. It helps manage numbers that need more precision, like those used in sound frequencies or scientific calculations.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>\u00b7<\/p>\n\n\n\n<p>The most complicated part of my code is the section that allows the user to play semitones. If you think of a piano keyboard, semitones are the black keys between the white ones. I realized that semitones are just the average frequency of two normal tones, so I decided to create a function to do that.<\/p>\n\n\n\n<p>I decided that the most straightforward way to add this feature was to define the semitone frequencies beforehand and just have the buzzer play that frequency when two buttons were pressed.<\/p>\n\n\n\n<p>For example, take a look at this snippet of the code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (digitalRead(buttonPin2) == LOW &amp;&amp; digitalRead(buttonPin3) == LOW) { \n        tone(buzzerPin, frequencies&#091;1]);<\/code><\/pre>\n\n\n\n<p>This line checks if &#8216;buttonPin2&#8217; and &#8216;buttonPin3&#8217; are both pressed (reading as &#8216;LOW&#8217;). If true, it plays the frequency for &#8216;C#&#8217;, which is the note between &#8216;C&#8217; and &#8216;D&#8217;. The frequency used is from the &#8216;frequencies&#8217; array at index &#8216;1&#8217;.<\/p>\n\n\n\n<p>\u00b7<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bonus Features<\/h2>\n\n\n\n<p>At this point, I had completed creating the fundamental features of a keyboard. However, I wanted my keyboard to be personalized and creative, so I thought of adding a special feature\/easter egg to play preset tunes when a specific combination of keys was pressed. I labeled all the buttons with numbers, and I ended up with an easter egg where &#8220;O Canada&#8221; plays when keys 1, 2, and 7 are pressed down simultaneously. The song is definitely recognizable when played, but some of the frequencies sound funny since I had to manually write out the frequency and duration of every single note. As I improve my knowledge of Arduinos, this is definitely something I want to look back on and perhaps create a more efficient solution for.<\/p>\n\n\n\n<p><strong>I also wrote sheet music for some famous tunes:<\/strong><\/p>\n\n\n\n<h5 class=\"wp-block-heading\">1. <strong>Twinkle Twinkle Little Star<\/strong><\/h5>\n\n\n\n<p>1 1 5 5 6 6 5<br>4 4 3 3 2 2 1<br>5 5 4 4 3 3 2<br>5 5 4 4 3 3 2<br>1 1 5 5 6 6 5<br>4 4 3 3 2 2 1<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">2. <strong>Mary Had a Little Lamb<\/strong><\/h5>\n\n\n\n<p>3 2 1 2 3 3 3<br>2 2 2 3 5 5<br>3 2 1 2 3 3 3<br>3 2 2 3 2 1<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">3. <strong>Ode to Joy<\/strong><\/h5>\n\n\n\n<p>3 3 4 5<br>5 4 3 2<br>1 1 2 3<br>3 2 2<\/p>\n\n\n\n<p>3 3 4 5<br>5 4 3 2<br>1 1 2 3<br>2 1 1<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">4. <strong>Jingle Bells<\/strong><\/h5>\n\n\n\n<p>3 3 3 3 3 3 3<br>3 5 1 2 3<br>4 4 4 4 4 3 3 3<br>3 2 2 3 2 5<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">5. <strong>Happy Birthday<\/strong><\/h5>\n\n\n\n<p>1 1 2 1 4 3<br>1 1 2 1 5 4<br>1 1 8 6 4 3 2<br>6 6 5 4 5 4<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-content\/uploads\/sites\/10\/2024\/10\/WhatsApp-Image-2024-10-14-at-16.18.16-1024x768.jpeg\" alt=\"\" class=\"wp-image-111\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-content\/uploads\/sites\/10\/2024\/10\/WhatsApp-Image-2024-10-14-at-16.18.16-1024x768.jpeg 1024w, https:\/\/wp.stgeorges.bc.ca\/timd\/wp-content\/uploads\/sites\/10\/2024\/10\/WhatsApp-Image-2024-10-14-at-16.18.16-300x225.jpeg 300w, https:\/\/wp.stgeorges.bc.ca\/timd\/wp-content\/uploads\/sites\/10\/2024\/10\/WhatsApp-Image-2024-10-14-at-16.18.16-768x576.jpeg 768w, https:\/\/wp.stgeorges.bc.ca\/timd\/wp-content\/uploads\/sites\/10\/2024\/10\/WhatsApp-Image-2024-10-14-at-16.18.16-1536x1152.jpeg 1536w, https:\/\/wp.stgeorges.bc.ca\/timd\/wp-content\/uploads\/sites\/10\/2024\/10\/WhatsApp-Image-2024-10-14-at-16.18.16.jpeg 1600w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">The keyboard with labeled keys<\/figcaption><\/figure>\n\n\n\n<p>\u00b7<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Demos<\/h2>\n\n\n\n<p>The TinkerCad replica of my keyboard isn&#8217;t great for demoing some features since TinkerCad doesn&#8217;t allow you to press multiple buttons down at once. So, I have recorded some of my project&#8217;s key features. You can watch them here:<\/p>\n\n\n\n<p><strong>Chromatic Scale<\/strong> (Playing every note)<\/p>\n\n\n\n<p><a href=\"https:\/\/drive.google.com\/file\/d\/1BL2zDV6yozJN9IC-TYLmPgb3PrmIsBlq\/view?usp=sharing\">https:\/\/drive.google.com\/file\/d\/1BL2zDV6yozJN9IC-TYLmPgb3PrmIsBlq\/view?usp=sharing<\/a><\/p>\n\n\n\n<p><strong>O Canada<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/drive.google.com\/file\/d\/1-pMouuPZQscaXoNydYdLbMY2INTcSyWg\/view?usp=sharing\">https:\/\/drive.google.com\/file\/d\/1-pMouuPZQscaXoNydYdLbMY2INTcSyWg\/view?usp=sharing<\/a><\/p>\n\n\n\n<p><strong>Ode To Joy Playing<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/drive.google.com\/file\/d\/1Zsy4S5iCmAXa2lMbp1wZEuwmQG9tN0Ga\/view?usp=sharing\">https:\/\/drive.google.com\/file\/d\/1Zsy4S5iCmAXa2lMbp1wZEuwmQG9tN0Ga\/view?usp=sharing<\/a><\/p>\n\n\n\n<p>\u00b7<\/p>\n\n\n\n<p>Overall, this project has been extremely rewarding, and I have learned many new skills related to coding and circuitry. I believe the code used in this project is redundant in some areas and could be a lot shorter and more efficient if smarter methods were used, so that&#8217;s something I wish to come back to improve in the future.<\/p>\n\n\n\n<p>\u00b7<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is my second mini-assignment out of the 3 Fusion self-paced assignments. My previous post documents my project on CAD, where I made a 3D model of a birdhouse with mechanical drawings and a BOM. For this particular robotics assignment, I must demonstrate my understanding of these skills through this blog post: I was provided [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-105","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-json\/wp\/v2\/posts\/105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-json\/wp\/v2\/comments?post=105"}],"version-history":[{"count":8,"href":"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-json\/wp\/v2\/posts\/105\/revisions"}],"predecessor-version":[{"id":117,"href":"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-json\/wp\/v2\/posts\/105\/revisions\/117"}],"wp:attachment":[{"href":"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-json\/wp\/v2\/media?parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-json\/wp\/v2\/categories?post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/timd\/wp-json\/wp\/v2\/tags?post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}