{"id":63,"date":"2019-10-22T07:03:34","date_gmt":"2019-10-22T07:03:34","guid":{"rendered":"https:\/\/starthardware.org\/en\/?p=63"},"modified":"2019-10-22T07:03:50","modified_gmt":"2019-10-22T07:03:50","slug":"unit-7-digital-out-your-first-program","status":"publish","type":"post","link":"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/","title":{"rendered":"Unit 7 \u2013 Digital Out: Your first program!"},"content":{"rendered":"\n<p>Did you build the circuit from <a href=\"https:\/\/starthardware.org\/en\/2019\/10\/22\/unit-6-digital-out-circuit\/\">Unit 6<\/a>? Perfect! If you already connected the Arduino to the computer plug it out again. Open the Arduino software on your computer and let\u2019s do two little adjustments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Select the Board<\/h2>\n\n\n\n<p>In the menu click on\u00a0<em>Tools > Board<\/em>\u00a0and select <em>Arduino UNO<\/em> like shown in the picture.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"692\" src=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-select-board.jpg\" alt=\"Arduino IDE select board \" class=\"wp-image-64\" srcset=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-select-board.jpg 1200w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-select-board-300x173.jpg 300w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-select-board-768x443.jpg 768w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-select-board-1024x591.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Select the Port<\/h2>\n\n\n\n<p>Now click on\u00a0<em>Tools > Port<\/em>. Remember the entries which you see here. Maybe you want to write them down. Now connect the Arduino with the USB cable and again click on\u00a0<em>Tools > Port<\/em>. Now you should see a new entry. (On a mac it looks like \u00ab\/dev\/tty.usbmodem\u2026.\u00bb, on Windows it usually looks like \u00abCOM\u2026\u00bb). Select the new entry and we are ready to go<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"692\" src=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-select-port.jpg\" alt=\"Arduino IDE select port\" class=\"wp-image-65\" srcset=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-select-port.jpg 1200w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-select-port-300x173.jpg 300w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-select-port-768x443.jpg 768w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-select-port-1024x591.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p>Now the Arduino software knows, which Arduino we are using and where it is connected to.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Arduino Programming<\/h3>\n\n\n\n<p>The white area of the Arduino software is the programming window. In here, we will write all the programming code. Write? Yes! Programming is nothing more than typing commands. The good news is: It will do what you say \ud83d\ude42<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"995\" src=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/6_3_arduino_software.jpg\" alt=\"Arduino IDE Software\" class=\"wp-image-66\" srcset=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/6_3_arduino_software.jpg 1200w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/6_3_arduino_software-300x249.jpg 300w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/6_3_arduino_software-768x637.jpg 768w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/6_3_arduino_software-1024x849.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p>Like in grammar there is spelling and grammar. Those rules are called syntax. Don\u2019t worry. You will learn that very fast. It is easy \ud83d\ude09<\/p>\n\n\n\n<p>If you want to program an Arduino, you have to write the following into the programming window. It is the base structure for every Arduino program:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void setup(){\n\n}\n\nvoid loop(){\n\n}<\/code><\/pre>\n\n\n\n<p>Looks odd? So here we have two method blocks. You can put commands into a method and the program will execute it. A command could be:\u00a0<em>Switch on a LED!<\/em> The curly brackets\u00a0<em>{ }<\/em>\u00a0open and close the method block. <\/p>\n\n\n\n<p>Everything in the brackets belongs to the method. The word\u00a0<em>void<\/em>\u00a0tells the Arduino that it is a method. After\u00a0<em>void<\/em>\u00a0comes the method name. In that case it is\u00a0<em>setup<\/em>\u00a0and\u00a0<em>loop<\/em>. After the method name there has to be an opening and closing normal bracket:\u00a0<em>()<\/em><\/p>\n\n\n\n<p>But don\u2019t worry about the syntax. You will learn it automatically and I will show you how it is written correctly.<\/p>\n\n\n\n<p>You can type the curly brackets on windows by pressing Alt-Gr + 7 and Alt-Gr + 0, on a Mac by pressing Alt + 8 and Alt + 9.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Expert Knowledge: Setup and Loop<\/h3>\n\n\n\n<p>Imagine you get a new bicycle. At first you have to set it up. You adjust the saddle and the handlebars. You only do this one time. And now? You sit on it and start to pedal. You push the left pedal, then you push the right one. And you do that over and over again. We could say, you loop that movement.<\/p>\n\n\n\n<p>So:&nbsp;<em>void setup()<\/em>&nbsp;is only executed one time while&nbsp;<em>void loop()<\/em>&nbsp;repeated over and over again.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void setup(){\n\n}<\/code><\/pre>\n\n\n\n<p>This part is only executed one time. It is the setup method.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void loop(){\n\n}<\/code><\/pre>\n\n\n\n<p>This part is repeated continuously like pedaling on a bike. It is an infinit loop an is called the loop method.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Command<\/h3>\n\n\n\n<p>Alright. And why is that helping us? Let\u2019s talk about what our program should do. It should switch on an LED.<\/p>\n\n\n\n<p>To do so we have to tell the Arduino that we would like to use a digital pin to switch something \u2013&nbsp;yes, our LED. This would convert the pin to an output pin. We have to do that only one single time. So it belongs into the setup method. We use the following command to tell the Arduino what it should do:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>pinMode(9,OUTPUT);<\/code><\/pre>\n\n\n\n<p>That is a great command. It consists of the keyword&nbsp;<em>pinMode<\/em>&nbsp;followed by two round brackets. Here we write two parameters. The first is the number of the pin. We connected the cable to pin 9 so we have to write a 9. The second parameter is he function we want to use. In this case we want to use the pin as an output, so we write OUTPUT (yes, all capital letters). Every command line has to end with a semicolon (;).<\/p>\n\n\n\n<p>So: Command name, opening round bracket, pin number, function, closing round bracket, semicolon -> That is the command \ud83d\ude09<\/p>\n\n\n\n<p>Now the Arduino knows that we want to use a pin as an output. Now we have to tell it that it should switch it on.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>digitalWrite(9, HIGH);<\/code><\/pre>\n\n\n\n<p>Looks similar to the first command, no? This command is named digitalWrite. It also gets parameters. Like pinMode the first parameter is the pin number (9). The second parameter is HIGH. That switches the pin on (LOW would switch it off). This time, we want to do this only one time, so you can write it into the setup<\/p>\n\n\n\n<p>Now, the program should look like that:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void setup(){\n  pinMode(9,OUTPUT);\n  digitalWrite(9, HIGH);\n}\n\nvoid loop(){\n\n}<\/code><\/pre>\n\n\n\n<p>If you hit the TAB key, the command lines move a bit to the right. It makes the program more easy to read. Alternatively you can go to the menu and click&nbsp;<em>Tools &gt; Auto Format<\/em>. The Arduino software will arrange everything nicely for you.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Upload<\/h3>\n\n\n\n<p>Now you have a beautiful program but the LED is still dark, right? That is because we have to upload the program to the Arduino board. In the menu click on&nbsp;<em>File &gt; Upload<\/em>. Now, you should see the yellow LEDs on the Arduino flashing for some time and afterwards your LED should light up.<\/p>\n\n\n\n<p>The LED is not lighting up? Check again if all cables are connected correctly. Sometimes, there are some spelling mistakes in the code. If so, you would see red text in the black area under the code window.<\/p>\n\n\n\n<p>It lights up? Congratulations!!! You wrote your first program! That is really great \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did you build the circuit from Unit 6? Perfect! If you already connected the Arduino to the computer plug it out again. Open the Arduino software on your computer and let\u2019s do two little adjustments. Select the Board In the menu click on\u00a0Tools > Board\u00a0and select Arduino UNO like shown in the picture. Select the&hellip;&nbsp;<a href=\"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Unit 7 \u2013 Digital Out: Your first program!<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":67,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[2],"tags":[],"class_list":["post-63","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Unit 7 \u2013 Digital Out: Your first program! - StartHardware - Tutorials for Arduino<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unit 7 \u2013 Digital Out: Your first program! - StartHardware - Tutorials for Arduino\" \/>\n<meta property=\"og:description\" content=\"Did you build the circuit from Unit 6? Perfect! If you already connected the Arduino to the computer plug it out again. Open the Arduino software on your computer and let\u2019s do two little adjustments. Select the Board In the menu click on\u00a0Tools &gt; Board\u00a0and select Arduino UNO like shown in the picture. Select the&hellip;&nbsp;Read More &raquo;Unit 7 \u2013 Digital Out: Your first program!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/\" \/>\n<meta property=\"og:site_name\" content=\"StartHardware - Tutorials for Arduino\" \/>\n<meta property=\"article:published_time\" content=\"2019-10-22T07:03:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-10-22T07:03:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-program.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Stefan Hermann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/starthardware.org\/en\/#website\",\"url\":\"https:\/\/starthardware.org\/en\/\",\"name\":\"StartHardware - Tutorials for Arduino\",\"description\":\"Arduino, Electronics, Fun\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/starthardware.org\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-program.jpg\",\"contentUrl\":\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-program.jpg\",\"width\":1200,\"height\":675,\"caption\":\"Arduino program blink\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/#webpage\",\"url\":\"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/\",\"name\":\"Unit 7 \u2013 Digital Out: Your first program! - StartHardware - Tutorials for Arduino\",\"isPartOf\":{\"@id\":\"https:\/\/starthardware.org\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/#primaryimage\"},\"datePublished\":\"2019-10-22T07:03:34+00:00\",\"dateModified\":\"2019-10-22T07:03:50+00:00\",\"author\":{\"@id\":\"https:\/\/starthardware.org\/en\/#\/schema\/person\/811b16fabcbfeef4210ea79cf0990a59\"},\"breadcrumb\":{\"@id\":\"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/starthardware.org\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unit 7 \u2013 Digital Out: Your first program!\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/starthardware.org\/en\/#\/schema\/person\/811b16fabcbfeef4210ea79cf0990a59\",\"name\":\"Stefan Hermann\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/starthardware.org\/en\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5b5a74ee1d07024fd1eff9b1f7137108089169010a93afaee907b9325ee579a6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5b5a74ee1d07024fd1eff9b1f7137108089169010a93afaee907b9325ee579a6?s=96&d=mm&r=g\",\"caption\":\"Stefan Hermann\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Unit 7 \u2013 Digital Out: Your first program! - StartHardware - Tutorials for Arduino","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/","og_locale":"en_US","og_type":"article","og_title":"Unit 7 \u2013 Digital Out: Your first program! - StartHardware - Tutorials for Arduino","og_description":"Did you build the circuit from Unit 6? Perfect! If you already connected the Arduino to the computer plug it out again. Open the Arduino software on your computer and let\u2019s do two little adjustments. Select the Board In the menu click on\u00a0Tools > Board\u00a0and select Arduino UNO like shown in the picture. Select the&hellip;&nbsp;Read More &raquo;Unit 7 \u2013 Digital Out: Your first program!","og_url":"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/","og_site_name":"StartHardware - Tutorials for Arduino","article_published_time":"2019-10-22T07:03:34+00:00","article_modified_time":"2019-10-22T07:03:50+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-program.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Written by":"Stefan Hermann","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/starthardware.org\/en\/#website","url":"https:\/\/starthardware.org\/en\/","name":"StartHardware - Tutorials for Arduino","description":"Arduino, Electronics, Fun","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/starthardware.org\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/#primaryimage","inLanguage":"en-US","url":"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-program.jpg","contentUrl":"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2019\/10\/arduino-program.jpg","width":1200,"height":675,"caption":"Arduino program blink"},{"@type":"WebPage","@id":"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/#webpage","url":"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/","name":"Unit 7 \u2013 Digital Out: Your first program! - StartHardware - Tutorials for Arduino","isPartOf":{"@id":"https:\/\/starthardware.org\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/#primaryimage"},"datePublished":"2019-10-22T07:03:34+00:00","dateModified":"2019-10-22T07:03:50+00:00","author":{"@id":"https:\/\/starthardware.org\/en\/#\/schema\/person\/811b16fabcbfeef4210ea79cf0990a59"},"breadcrumb":{"@id":"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/starthardware.org\/en\/unit-7-digital-out-your-first-program\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/starthardware.org\/en\/"},{"@type":"ListItem","position":2,"name":"Unit 7 \u2013 Digital Out: Your first program!"}]},{"@type":"Person","@id":"https:\/\/starthardware.org\/en\/#\/schema\/person\/811b16fabcbfeef4210ea79cf0990a59","name":"Stefan Hermann","image":{"@type":"ImageObject","@id":"https:\/\/starthardware.org\/en\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/5b5a74ee1d07024fd1eff9b1f7137108089169010a93afaee907b9325ee579a6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5b5a74ee1d07024fd1eff9b1f7137108089169010a93afaee907b9325ee579a6?s=96&d=mm&r=g","caption":"Stefan Hermann"}}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts\/63","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":1,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"predecessor-version":[{"id":68,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts\/63\/revisions\/68"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/media\/67"}],"wp:attachment":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}