








{"id":107,"date":"2020-10-12T21:23:48","date_gmt":"2020-10-12T21:23:48","guid":{"rendered":"https:\/\/osoyoo.info\/?p=107"},"modified":"2020-10-13T22:10:50","modified_gmt":"2020-10-13T22:10:50","slug":"arduino-basic-lesson-18-osoyoo-relay-module","status":"publish","type":"post","link":"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-18-osoyoo-relay-module\/","title":{"rendered":"Hardware Programming with Arduino IDE &#8211; Lesson 18: OSOYOO Relay Module"},"content":{"rendered":"<p><a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/lesson-17-dht11-sensor\/\"><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-20-servo\/\"><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\">About the OSOYOO Relay Module<\/a>\n<ul>\n<li><a href=\"#3.1\">Overview<\/a><\/li>\n<li><a href=\"#3.2\">Features<\/a><\/li>\n<li><a href=\"#3.3\">Pins Out<\/a><\/li>\n<li><a href=\"#3.4\">Input<\/a><\/li>\n<li><a href=\"#3.5\">Output<\/a><\/li>\n<li><a href=\"#3.7\">How relay works?<\/a><\/li>\n<li><a href=\"#3.8\">High Voltage Warning<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#4\">Example<\/a>\n<ul>\n<li><a href=\"#5\">Connection<\/a><\/li>\n<li><a href=\"#6\">Upload Sketch<\/a><\/li>\n<li><a href=\"#7\">Program Running Result<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h1 id=\"1\">Introduction<\/h1>\n<p>A relay is an electrically operated switch. Many relays use an electromagnet to mechanically operate a switch, but other operating principles are also used, such as solid-state relays. Relays are used where it is necessary to control a circuit by a separate low-power signal, or where several circuits must be controlled by one signal.<\/p>\n<p>In this lesson, we will show you how the OSOYOO Relay Module works and how to use it with the Osoyoo Uno board to control high voltage devices.<\/p>\n<pre>Note: In this lesson, we set the relay module to be active high<\/pre>\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 for Arduino x1<\/li>\n<li>OSOYOO 1-Channel Relay Module x 1<\/li>\n<li>OSOYOO 3-pin PnP cable 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<ul>\n<li>Arduino IDE (version 1.6.4+)<\/li>\n<\/ul>\n<h1 id=\"3\">About OSOYOO Relay Module<\/h1>\n<p><img loading=\"lazy\" class=\"aligncenter size-full\" src=\"https:\/\/osoyoo.com\/picture\/Micro_bit_STEM\/Home_Appliance_Control\/DSC_6702.jpg\" width=\"1000\" height=\"392\" \/><\/p>\n<h2 id=\"3.1\">Overview<\/h2>\n<p>This is a 5V 1-Channel Relay Module board, Be able to control various appliances, and other equipment with large current. It can be controlled directly by Microcontroller (Raspberry Pi, Arduino, 8051, AVR, PIC, DSP, ARM, ARM, MSP430, TTL logic). Very useful project for application like Micro-Controller based projects, Remote controller, Lamp on Off, and any circuits which required isolated high current and high voltage switching by applying any TTL or CMOS level voltage.<\/p>\n<pre><\/pre>\n<h2 id=\"3.2\">Features<\/h2>\n<ul>\n<li>High current relay, AC250V 10A, DC30V 10A<\/li>\n<li>1 LED to indicate when relays are on<\/li>\n<li>PWR LED indicator<\/li>\n<li>Works logic level: 5V<\/li>\n<li>Opto isolation circuitry<\/li>\n<\/ul>\n<h2 id=\"3.3\">Pins Out<\/h2>\n<p><img loading=\"lazy\" class=\"aligncenter size-full\" src=\"http:\/\/osoyoo.com\/picture\/OSOYOO_PnP_Kit_for_Arduino\/Lesson19\/Pinout.jpg\" width=\"1000\" height=\"570\" \/><\/p>\n<h2 id=\"3.4\">Input<\/h2>\n<p>It has a 1*3(2.54mm pitch) XH2.54 header for connecting power (5V and 0V), and for controlling the relay. The pins are marked on the PCB:<\/p>\n<ul>\n<li>GND &#8211; Connect 0V to this pin.<\/li>\n<li>VCC &#8211; Connect 5V to this pin. Is used to power the opto couplers<\/li>\n<li>SIG &#8211; Controls relay, you can select high level active or low level active through the jumper on the pcb board<\/li>\n<\/ul>\n<h2 id=\"3.5\">Output<\/h2>\n<p>This relay module could be considered like a series switches: 1 normally Open (NO), 1 normally closed (NC) and 1 common Pin (COM).<\/p>\n<ul>\n<li>COM- Common pin<\/li>\n<li>NC- Normally Closed<\/li>\n<li>NO- Normally Open<\/li>\n<\/ul>\n<h2 id=\"3.7\">How relay works?<\/h2>\n<p>The working of a relay can be better understood by explaining the following diagram given below.<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/07\/Relay-Design.jpg\"><img loading=\"lazy\" class=\"wp-image-9800 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/07\/Relay-Design.jpg\" alt=\"\" width=\"513\" height=\"287\" \/><\/a><\/p>\n<p>There are 5 parts in every relay:<\/p>\n<p>1. <strong>Electromagnet <\/strong>\u2013 It consists of an iron core wounded by coil of wires. When electricity is passed through, it becomes magnetic. Therefore, it is called electromagnet.<\/p>\n<p>2. <strong>Armature <\/strong>\u2013 The movable magnetic strip is known as armature. When current flows through them, the coil is it energized thus producing a magnetic field which is used to make or break the normally open (N\/O) or normally close (N\/C) points. And the armature can be moved with direct current (DC) as well as alternating current (AC).<\/p>\n<p>3. <strong>Spring<\/strong> \u2013 When no currents flow through the coil on the electromagnet, the spring pulls the armature away so the circuit cannot be completed.<\/p>\n<p>4. Set of electrical <strong>contacts<\/strong> \u2013 There are two contact points:<\/p>\n<p class=\"1\">\uff0eNormally open &#8211; connected when the relay is activated, and disconnected when it is inactive.<\/p>\n<p class=\"1\">\uff0eNormally close \u2013 not connected when the relay is activated, and connected when it is inactive.<\/p>\n<p>5. Molded frame \u2013 Relays are covered with plastic for protection.<\/p>\n<p><strong>Principle<\/strong><\/p>\n<p>The diagram shows an inner section diagram of a relay. An iron core is surrounded by a control coil. As shown, the power source is given to the electromagnet through a control switch and through contacts to the load. When current starts flowing through the control coil, the electromagnet starts energizing and thus intensifies the magnetic field. Thus the upper contact arm starts to be attracted to the lower fixed arm and thus closes the contacts causing a short circuit for the power to the load. On the other hand, if the relay was already de-energized when the contacts were closed, then the contact move oppositely and make an open circuit.<\/p>\n<p>As soon as the coil current is off, the movable armature will be returned by a force back to its initial position. This force will be almost equal to half the strength of the magnetic force. This force is mainly provided by two factors. They are the spring and also gravity.<\/p>\n<p>Relays are mainly made for two basic operations. One is low voltage application and the other is high voltage. For low voltage applications, more preference will be given to reduce the noise of the whole circuit. For high voltage applications, they are mainly designed to reduce a phenomenon called arcing.<\/p>\n<h2 id=\"3.8\" class=\"widget-title\">High Voltage Warning<\/h2>\n<hr \/>\n<p>Before we continue with this lesson, I will warn you here that we will use High Voltage which if incorrectly or improperly used could result in serious injuries or death. So be very caution of what you are doing.<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/07\/images.png\"><img loading=\"lazy\" class=\"size-full wp-image-9798 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/07\/images.png\" alt=\"\" width=\"267\" height=\"189\" \/><\/a><\/p>\n<h1 id=\"4\">Examples<\/h1>\n<h2>Using the Arduino to Control the Relay<\/h2>\n<p>In this example, when a HIGH level is supplied to signal terminal of the relay module, the LED on the relay will light up. Otherwise, it will turn off. If a periodic high and low level is supplied to the signal terminal, you can see the LED will cycle between on and off.<\/p>\n<h2 id=\"5\">Connection<\/h2>\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 OSOYOO 1-Channel Relay Module to the port D3 of the Magic I\/O shield with 3-pin PNP cables as below:<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full\" src=\"http:\/\/osoyoo.com\/picture\/OSOYOO_PnP_Kit_for_Arduino\/Lesson19\/relay.jpg\" width=\"1000\" height=\"459\" \/><\/p>\n<h2 id=\"6\">Code Program<\/h2>\n<p>After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled <strong>PWR<\/strong>) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. Then load up <a href=\"http:\/\/osoyoo.com\/picture\/ESP-01-PROGRAMMER\/OSOYOO_RELAY.zip\" target=\"_blank\" rel=\"noopener noreferrer\">the following sketch<\/a> onto your Arduino.<\/p>\n<pre><span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">SIG<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #000000;\">3<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #00979c;\">void<\/span> <span style=\"color: #5e6d03;\">setup<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #000000;\">{<\/span>\r\n \u00a0<span style=\"color: #434f54;\">\/\/ initialize digital pin LED_BUILTIN as an output.<\/span>\r\n \u00a0<span style=\"color: #d35400;\">pinMode<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">SIG<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #00979c;\">OUTPUT<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #434f54;\">\/\/ the loop function runs over and over again forever<\/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> <span style=\"color: #000000;\">{<\/span>\r\n \u00a0<span style=\"color: #d35400;\">digitalWrite<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">SIG<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #00979c;\">HIGH<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \u00a0\u00a0<span style=\"color: #434f54;\">\/\/ turn the LED on (HIGH is the voltage level)<\/span>\r\n \u00a0<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #434f54;\">\/\/ wait for a second<\/span>\r\n \u00a0<span style=\"color: #d35400;\">digitalWrite<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">SIG<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #00979c;\">LOW<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \u00a0\u00a0\u00a0<span style=\"color: #434f54;\">\/\/ turn the LED off by making the voltage LOW<\/span>\r\n \u00a0<span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">1000<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span style=\"color: #434f54;\">\/\/ wait for a second<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<\/pre>\n<h2 id=\"7\">Running Result<\/h2>\n<p>A few seconds after the upload finishes, you should see the LED cycle between on and off.<\/p>\n<p><center><iframe src=\"https:\/\/www.youtube.com\/embed\/rRTnlfolG4A\" width=\"1280\" height=\"753\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/center><a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/lesson-17-dht11-sensor\/\"><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-20-servo\/\"><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 About the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":160,"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\/107"}],"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=107"}],"version-history":[{"count":4,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/107\/revisions"}],"predecessor-version":[{"id":115,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/107\/revisions\/115"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/media\/160"}],"wp:attachment":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/media?parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/categories?post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/tags?post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}