








{"id":74,"date":"2020-10-12T20:11:21","date_gmt":"2020-10-12T20:11:21","guid":{"rendered":"https:\/\/osoyoo.info\/?p=74"},"modified":"2020-10-13T22:04:35","modified_gmt":"2020-10-13T22:04:35","slug":"arduino-basic-lesson-9-flowing-water-light","status":"publish","type":"post","link":"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-9-flowing-water-light\/","title":{"rendered":"Hardware Programming with Arduino IDE &#8211;  Lesson 9: Flowing Water Light"},"content":{"rendered":"<p><a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-8-use-serial-port-to-control-led\/\"><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\/12\/arduino-basic-lesson-10-pwm-control-led-brightnessbreathing-light\/\"><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><a href=\"https:\/\/www.amazon.com\/dp\/B08J7DKJK9?ref=myi_title_dp\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/us_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.co.uk\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone\" src=\"https:\/\/osoyoo.com\/picture\/icon\/uk_buy_now.png\" alt=\"\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.de\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/de_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.it\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/it_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.fr\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/fr_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.es\/dp\/B08J6BL2P7\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/es_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.amazon.co.jp\/dp\/B08J7TLP48\"><img loading=\"lazy\" class=\"alignnone size-large\" src=\"https:\/\/osoyoo.com\/picture\/icon\/jp_buy_now.png\" width=\"150\" height=\"30\" \/><\/a><\/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\">Connection<\/a><\/li>\n<li><a href=\"#4\">Upload Sketch<\/a><\/li>\n<li><a href=\"#5\">Program Running Result<\/a><\/li>\n<\/ol>\n<h1 id=\"1\">Introduction<\/h1>\n<p><a href=\"https:\/\/osoyoo.com\/?p=34330\">The OSOYOO Magic I\/O Shield for Arduino<\/a>\u00a0is a powerful board for the beginners. With this Magic board, we can\u00a0 easily connect various sensors and actuators much easier than before.<\/p>\n<p><span id=\"w_114\">In this lesson we will use Arduino to drive 4 LEDs \u00a0and make a running LED light row.<\/span><\/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>OSOYOO Magic I\/O Shield V1.1 x 1<\/li>\n<li>OSOYOO LED Module x 4<\/li>\n<li>OSOYOO 3-Pin PnP cable x4<\/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<h1 id=\"3\">Connection<\/h1>\n<p>First, please plug OSOYOO Magic I\/O shield into UNO board:<\/p>\n<p><img loading=\"lazy\" class=\"size-full aligncenter\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/lesson4\/UNO%2BBase-min.png\" width=\"1000\" height=\"600\" \/><\/p>\n<p>Then connect the LED module to the ports of the Magic I\/O shield with four 3-pin PNP cables as below:<\/p>\n<p>White \u2013 D2<\/p>\n<p>Red \u2013 D3<\/p>\n<p>Yellow \u2013 D4<\/p>\n<p>Green \u2013 D5<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full\" src=\"https:\/\/osoyoo.com\/picture\/OSOYOO_PnP_Kit_for_Arduino\/picture\/magic-4led.jpg\" width=\"1000\" height=\"600\" \/><\/p>\n<p><strong>Note:<\/strong><\/p>\n<p>You should NOT connect a \u00a0normal LED between 5V and GND \u00a0pins in Arduino without a resistance. First, This will cause too much current passing through LED and burn it out. Second, the LED polarity is wrongly connected(i.e Positive Pin connected to GND pin) will also damage the LED.<\/p>\n<p>To solve such problem. \u00a0we designed OSOYOO LED module which has a build-in resistance to limit the current and fixed polarity socket to avoid these mistakes. \u00a0In this project, we will use OSOYOO LED module.<\/p>\n<h1 id=\"4\">Upload Sketch<\/h1>\n<p>If you have connected the wiring diagram, connect the Arduino UNO board to your computer using the USB cable. The green power LED (labelled <strong>PWR<\/strong>) should go on.<\/p>\n<p><img class=\"aligncenter\" src=\"https:\/\/osoyoo.com\/picture\/Arduino_Graphical_Programming_Kit\/lesson1\/uno-pc.png\" \/><\/p>\n<p>Open the Arduino IDE,and choose the corresponding board type and port type for your Arduino\uff0cthen <a href=\"https:\/\/osoyoo.com\/picture\/OSOYOO_PnP_Kit_for_Arduino\/code\/Lesson10_Four_of_Flowing_Water_Light.rar\" target=\"_blank\" rel=\"noopener noreferrer\">open the sketch<\/a> or copy below code to your IDE window:<\/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 \u00a0<span style=\"color: #5e6d03;\">for<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">i<\/span><span style=\"color: #434f54;\">=<\/span><span style=\"color: #000000;\">2<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">i<\/span><span style=\"color: #434f54;\">&lt;=<\/span><span style=\"color: #000000;\">5<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">i<\/span><span style=\"color: #434f54;\">++<\/span><span style=\"color: #000000;\">)<\/span> \u00a0\u00a0\u00a0<span style=\"color: #434f54;\">\/\/Set the pin2~pin8 cycle output<\/span>\r\n \u00a0<span style=\"color: #000000;\">{<\/span>\r\n \u00a0\u00a0\u00a0<span style=\"color: #d35400;\">pinMode<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">i<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #00979c;\">OUTPUT<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n \u00a0<span style=\"color: #000000;\">}<\/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 \u00a0<span style=\"color: #5e6d03;\">for<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">x<\/span><span style=\"color: #434f54;\">=<\/span><span style=\"color: #000000;\">2<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">x<\/span><span style=\"color: #434f54;\">&lt;=<\/span><span style=\"color: #000000;\">5<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #000000;\">x<\/span><span style=\"color: #434f54;\">++<\/span><span style=\"color: #000000;\">)<\/span> \u00a0\u00a0<span style=\"color: #434f54;\">\/\/Each LED will flash in one second<\/span>\r\n \u00a0<span style=\"color: #000000;\">{<\/span>\r\n \u00a0\u00a0\u00a0<span style=\"color: #d35400;\">digitalWrite<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">x<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #00979c;\">HIGH<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n \u00a0\u00a0\u00a0<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">500<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n \u00a0\u00a0\u00a0<span style=\"color: #d35400;\">digitalWrite<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">x<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #00979c;\">LOW<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n \u00a0\u00a0\u00a0<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">500<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n \u00a0<span style=\"color: #000000;\">}<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<\/pre>\n<p>Now, simply click the &#8220;Upload&#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\/arduinoide.png\"><img loading=\"lazy\" class=\"size-full wp-image-7672 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/06\/arduinoide.png\" alt=\"\" width=\"487\" height=\"593\" \/><\/a><\/p>\n<h1 id=\"5\">Running Result<\/h1>\n<p>Now, you should see four LEDs lighting one by one \u00a0as per following video, this whole process will repeat until the circuit is powered off.<\/p>\n<div align=\"center\"><iframe src=\"https:\/\/www.youtube.com\/embed\/Gx_4IjVHDJo\" width=\"853\" height=\"480\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/div>\n<div align=\"center\">\n<p><a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-8-use-serial-port-to-control-led\/\"><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\/12\/arduino-basic-lesson-10-pwm-control-led-brightnessbreathing-light\/\"><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<\/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 Connection Upload [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":151,"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\/74"}],"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=74"}],"version-history":[{"count":2,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":80,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/74\/revisions\/80"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/media\/151"}],"wp:attachment":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}