








{"id":61,"date":"2020-10-11T20:24:30","date_gmt":"2020-10-11T20:24:30","guid":{"rendered":"https:\/\/osoyoo.info\/?p=61"},"modified":"2020-10-13T21:58:50","modified_gmt":"2020-10-13T21:58:50","slug":"arduino-basic-lesson-6-your-first-arduino-program-hello-world","status":"publish","type":"post","link":"https:\/\/osoyoo.info\/index.php\/2020\/10\/11\/arduino-basic-lesson-6-your-first-arduino-program-hello-world\/","title":{"rendered":"Hardware Programming with Arduino IDE \u2013 Lesson 6: Your first Arduino program &#8220;Hello World!&#8221;"},"content":{"rendered":"<p><a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/11\/arduino-basic-lesson-5-what-is-a-sketch-and-how-does-it-work\/\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Previous.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/11\/arduino-basic-tutorial-directory\/\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Tutorial.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/11\/arduino-basic-lesson-7-blink\/\"><img loading=\"lazy\" class=\"alignright\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Next.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a><\/p>\n<div align=\"center\">\n<div align=\"center\"><img class=\"aligncenter\" src=\"https:\/\/osoyoo.com\/picture\/icon\/authorized_retailers.png\" \/><\/div>\n<div align=\"center\"><\/div>\n<table>\n<tbody>\n<tr>\n<td>Buy from US<\/td>\n<td>Buy from UK<\/td>\n<td>Buy from DE<\/td>\n<td>Buy from IT<\/td>\n<td>Buy from FR<\/td>\n<td>Buy from ES<\/td>\n<td>Buy from JP<\/td>\n<\/tr>\n<tr>\n<td><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/us_buy_now.png\" width=\"150\" height=\"30\" \/><\/td>\n<td><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/icon\/uk_buy_now.png\" alt=\"\" width=\"150\" height=\"30\" \/><\/td>\n<td><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/de_buy_now.png\" width=\"150\" height=\"30\" \/><\/td>\n<td><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/it_buy_now.png\" width=\"150\" height=\"30\" \/><\/td>\n<td><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/fr_buy_now.png\" width=\"150\" height=\"30\" \/><\/td>\n<td><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/es_buy_now.png\" width=\"150\" height=\"30\" \/><\/td>\n<td><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/jp_buy_now.png\" width=\"150\" height=\"30\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2><strong>Content<\/strong><\/h2>\n<ol>\n<li><a href=\"#1\">Introduction<\/a><\/li>\n<li><a href=\"#2\">Preparations<\/a>\n<ul>\n<li><a href=\"#2.1\">Hardware<\/a><\/li>\n<li><a href=\"#2.2\">Software<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#3\">Upload Sketch<\/a>\n<ul>\n<li><a href=\"#3.1\">Select Board Type Arduino UNO<\/a><\/li>\n<li><a href=\"#3.2\">Select Corresponding Serial Port<\/a><\/li>\n<li><a href=\"#3.3\">Open Hello World Sketch<\/a><\/li>\n<li><a href=\"#3.4\">Verify \/ Compile the Sketch<\/a><\/li>\n<li><a href=\"#3.5\">Upload<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#4\">Program Running Result<\/a><\/li>\n<\/ol>\n<h1 id=\"1\">Introduction<\/h1>\n<p>A &#8220;Hello, World!&#8221; program is traditionally used to introduce novice programmers to a programming language.<\/p>\n<p>&#8220;Hello, world!&#8221; is also traditionally used in a sanity test to make sure that a computer language is correctly installed, and that the operator understands how to use it, so our Arduino tutorial begins with Hello world.<\/p>\n<p>This lesson will basically get you up and running using the Arduino software and uploading a sketch to the Arduino board. Once you&#8217;ve completed this step we can continue to the really exciting stuff, which is when we start writing our own sketches!<\/p>\n<h1 id=\"2\">Preparations<\/h1>\n<h2 id=\"2.1\">Hardware<\/h2>\n<ul>\n<li>Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1<\/li>\n<li>USB Cable x 1<\/li>\n<li>PC x 1<\/li>\n<\/ul>\n<h2 id=\"2.2\">Software<\/h2>\n<p>Arduino IDE (version 1.6.4+)<\/p>\n<p><strong>Notice:<\/strong><\/p>\n<p>Not much is needed for this lesson,make sure you&#8217;ve gone through Preparation lessons first! These lessons assume you have installed Arduino IDE software and drivers!<\/p>\n<p>Make sure you have a good quality syncing cable,do not pick a &#8216;charge only&#8217; USB cable<\/p>\n<h1 id=\"3\">Upload Sketch<\/h1>\n<p>Connect your Osoyoo UNO board to the Computer via a A to B USB cable,then double click the Arduino software icon on your desktop.<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/arduino-icon.png\"><img loading=\"lazy\" class=\"size-full wp-image-7081 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/arduino-icon.png\" alt=\"\" width=\"110\" height=\"115\" \/><\/a><\/p>\n<p>To open up the workspace, also called the IDE. IDE stands for <strong>I<\/strong>ntegrated <strong>D<\/strong>evelopment <strong>E<\/strong>nvironment. Basically, a word processor for writing code.<\/p>\n<p>It looks like below:<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/ide-page.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-7379 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/ide-page.jpg\" alt=\"\" width=\"488\" height=\"595\" \/><\/a><\/p>\n<p>The main IDE window has multiple tabs and areas, we&#8217;ll visit all of these shortly, so keep your eye on this diagram!<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/ide-introduction.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-7097 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/ide-introduction.jpg\" alt=\"\" width=\"486\" height=\"593\" \/><\/a><\/p>\n<h2 id=\"3.1\">Select Board Type <strong>Arduino UNO<\/strong><\/h2>\n<p>Under the <strong>Tools<\/strong> menu, find the <strong>Board<\/strong> submenu and navigate that to select <strong>Arduino (Genuino) UNO<\/strong>.<\/p>\n<p>You should use this board selection also if you are using any other <strong>Arduino UNO compatible board<\/strong><\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/select-board-type.jpg\"><img loading=\"lazy\" class=\"wp-image-7098 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/select-board-type.jpg\" alt=\"\" width=\"468\" height=\"449\" \/><\/a><\/p>\n<h2 id=\"3.2\">Select Corresponding Serial Port<\/h2>\n<p>It&#8217;s very important to select the correct Serial port. <strong>This is where people can get tripped up<\/strong>. The good news is if you have a Arduino UNO compatible board, the name will appear next to the serial port menu item to make it easy to pick out!<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/select-corresponding-serial-port.jpg\"><img loading=\"lazy\" class=\"wp-image-7101 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/select-corresponding-serial-port.jpg\" alt=\"\" width=\"521\" height=\"458\" \/><\/a><\/p>\n<p>If you have another Arduino compatible board, you may not see anything after the Serial port name, but it will still be the only option available that is <em>not<\/em> COM1 or something with Bluetooth in the name.<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/portselection2.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-7138 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/portselection2.jpg\" alt=\"\" width=\"529\" height=\"593\" \/><\/a><\/p>\n<p><strong>Notice of port selection:<\/strong><\/p>\n<p><strong>Windows: <\/strong>The arduino compatiable port will nerver be COM1,don&#8217;t choose this one.You should only have one other option.<\/p>\n<p><strong>Mac OS X<\/strong> and <strong>Linux<\/strong>: It will never be an option with &#8216;bluetooth&#8217; in the name, look for\/dev\/cu.usbmodemor\/dev\/cu.usbserialor\/dev\/ttyUSBor similar!<\/p>\n<p>If your computer have lots of Serial ports, try unplugging your Arduino and seeing which port disappears next time you look at the Ports list!<\/p>\n<h2 id=\"3.3\">Open Hello World Sketch<\/h2>\n<p><a href=\"https:\/\/osoyoo.com\/2017\/06\/27\/what-is-a-sketch-and-how-does-it-work\/\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Sketches<\/strong> <\/a>are little scripts that you can send to the Arduino to tell it how to act. Let&#8217;s open up an <strong><a href=\"https:\/\/osoyoo.com\/download\/code\/hello_world.zip\" target=\"_blank\" rel=\"noopener noreferrer\">Example Sketch<\/a>.<\/strong>Download this file and unzip it,or copy below code to your new Arduino IDE window,don&#8217;t forget to save the code.<\/p>\n<pre><span style=\"color: #00979c;\">void<\/span> <span style=\"color: #5e6d03;\">setup<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span> \r\n<span style=\"color: #000000;\">{<\/span> \r\n<b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">begin<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">9600<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;\r\n<\/span><span style=\"color: #434f54;\">\/\/Set the baudrate to 9600,make sure it's same as your software settings<\/span> \r\n<span style=\"color: #434f54;\">\/\/When accessing other devices (such as Bluetooth), we also have to agree<\/span> \r\n<span style=\"color: #434f54;\">\/\/with the baudrate of other devices.<\/span> \r\n<span style=\"color: #000000;\">}<\/span> \r\n<span style=\"color: #00979c;\">void<\/span> <span style=\"color: #5e6d03;\">loop<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span> \r\n<span style=\"color: #000000;\">{<\/span> \r\n<b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">println<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\"Hello World!\"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;\r\n<\/span><span style=\"color: #434f54;\">\/\/The serial will print strings:\"Hello World!\"<\/span> \r\n<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">5000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;\r\n<\/span><span style=\"color: #434f54;\">\/\/ delay for 5 seconds(You can also change this numbers to config the delay time)<\/span> \r\n<span style=\"color: #000000;\">}<\/span><\/pre>\n<p>You will see the sketch windows as below:<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/helloworldsketch-2.jpg\"><img loading=\"lazy\" class=\"wp-image-7240 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/helloworldsketch-2.jpg\" alt=\"\" width=\"485\" height=\"592\" \/><\/a><\/p>\n<h2 id=\"3.4\">Verify \/ Compile the Sketch<\/h2>\n<p>The first step to getting a Sketch ready for transfer over to the arduino is to Verify\/Compile it. That means check it over for mistakes (sort of like spell-checking or grammatical editing) and then translate it into an app that is compatible with the Arduino hardware.<\/p>\n<p>We can start this action via the Verify button or the Sketch menu:<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/verify.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-7281 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/verify.jpg\" alt=\"\" width=\"486\" height=\"593\" \/><\/a><\/p>\n<p>After a few seconds, you should see the messageDone compiling.in the <strong>Status Bar<\/strong> andSketch uses &#8230; bytes (x%) of program storage space(or something similar) in the <strong>Program Notification Area.<\/strong><\/p>\n<p>This means the sketch was well-written and is ready for uploading to the Arduino board!<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/donecompiling.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-7283 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/donecompiling.jpg\" alt=\"\" width=\"486\" height=\"166\" \/><\/a><\/p>\n<h2 id=\"3.5\">Upload<\/h2>\n<p>Now, simply click the &#8220;<strong>Upload<\/strong>&#8221; button in the environment. Wait a few seconds &#8211; you should see the RX and TX leds on the board flashing. If the upload is successful, the message &#8220;Done uploading.&#8221; will appear in the status bar.<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/uploadbutton.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-7292 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/uploadbutton.jpg\" alt=\"\" width=\"486\" height=\"118\" \/><\/a><\/p>\n<p>After a few seconds you should get this screen, with the message <strong>Done uploading.<\/strong> in the status bar.<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/doneuploading.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-7294 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/doneuploading.jpg\" alt=\"\" width=\"486\" height=\"146\" \/><\/a><\/p>\n<h1 id=\"4\">Program Running Result<\/h1>\n<p>A few seconds after the upload finishes, you should see the TX LED on the board start to blink (in orange).Click the Serial Monitor button:<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/serialbutton.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-7308 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/serialbutton.jpg\" alt=\"\" width=\"485\" height=\"117\" \/><\/a><\/p>\n<p>Make sure the serial monitor&#8217;s COM port is corresponding to your Arduino port, and check if the serial monitor Baudrate is same as your sketch setting? If yes,you will see the Arduino serial output the string &#8220;Hello World&#8221; every 5 seconds :<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/serialmonitoroutput.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-7315 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/serialmonitoroutput.jpg\" alt=\"\" width=\"598\" height=\"365\" \/><\/a><\/p>\n<p>If you have compeleted all operations and the program running successfully\uff0ccongratulations\uff01You&#8217;ve gotten Arduino up-and-running. If you have problems, please see the <a class=\"wikilink\" href=\"http:\/\/www.arduino.cc\/en\/Guide\/Troubleshooting\" target=\"_blank\" rel=\"noopener noreferrer\">troubleshooting suggestions<\/a> on the www.arduino.cc.<\/p>\n<p><a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/11\/arduino-basic-lesson-5-what-is-a-sketch-and-how-does-it-work\/\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Previous.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/11\/arduino-basic-tutorial-directory\/\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Tutorial.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/11\/arduino-basic-lesson-7-blink\/\"><img loading=\"lazy\" class=\"alignright\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/Next.png\" alt=\"\" width=\"206\" height=\"59\" \/><\/a><\/p>\n<div align=\"center\">\n<div align=\"center\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES Buy from JP Content Introduction Preparations Hardware Software Upload Sketch [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":148,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/61"}],"collection":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/comments?post=61"}],"version-history":[{"count":4,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/61\/revisions"}],"predecessor-version":[{"id":70,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/61\/revisions\/70"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/media?parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/categories?post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/tags?post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}