








{"id":116,"date":"2020-10-12T21:30:21","date_gmt":"2020-10-12T21:30:21","guid":{"rendered":"https:\/\/osoyoo.info\/?p=116"},"modified":"2020-10-13T22:12:03","modified_gmt":"2020-10-13T22:12:03","slug":"arduino-basic-lesson-20-ir-remote-control","status":"publish","type":"post","link":"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-20-ir-remote-control\/","title":{"rendered":"Hardware Programming with Arduino IDE &#8211; Lesson 20: IR Remote Control"},"content":{"rendered":"<p><a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-19-servo\/\"><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-21-mini-fan\/\"><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 IR<\/a>\n<ul>\n<li><a href=\"#3.1\">What is IR?<\/a><\/li>\n<li><a href=\"#3.2\">Modulation<\/a><\/li>\n<li><a href=\"#3.3\">Technical Details of VS1838B IR Receiver<\/a><\/li>\n<li><a href=\"#3.4\">The pinout for VS1838B IR Receiver:<\/a><\/li>\n<li><a href=\"#3.5\">About the IR control<\/a><\/li>\n<li><a href=\"#3.6\">IR-REMOTE LIBRARY<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#4\">Examples<\/a>\n<ul>\n<li><a href=\"#4.1\">Read codes from IR Remote<\/a>\n<ul>\n<li><a href=\"#4.1.1\">Connection<\/a><\/li>\n<li><a href=\"#4.1.2\">Code Program<\/a><\/li>\n<li><a href=\"#4.1.3\">Running Result<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#4.2\">IR Remote Test<\/a>\n<ul>\n<li><a href=\"#4.2.1\">Code Program<\/a><\/li>\n<li><a href=\"#4.2.2\">Running Result<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#4.3\">IR Control LED<\/a>\n<ul>\n<li><a href=\"#4.3.1\">Connection<\/a><\/li>\n<li><a href=\"#4.3.2\">Code Program<\/a><\/li>\n<li><a href=\"#4.3.3\">Running Result<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h1 id=\"1\">Introduction<\/h1>\n<p>IR, or infrared, communication is a common, inexpensive, and easy to use wireless communication technology. IR light is very similar to visible light, except that it has a slightlty longer wavelength. This means IR is undetectable to the human eye &#8211; perfect for wireless communication. For example, when you hit a button on your TV remote, an IR LED repeatedly turns on and off, 38,000 time a second, to transmit information (like volume or channel control) to an IR photo sensor on your TV.<\/p>\n<p>This tutorial will first explain the inner workings of common IR communication protocols. Then we will go over three examples that will allow you to transmit and receive IR data using an Arduino. In the first example, we will read incoming IR data from a common remote control using the 1838B IR photo sensor. The next example will show you how to test the IR remote and print the corrsponding button name on the Serial Monitor. The third example will show you how to transmit data from an IR receiver to control a common appliance, such as turn on an LED.<\/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 Infrared Receiver module x 1<\/li>\n<li>Infrared Remote Controller x 1<\/li>\n<li>OSOYOO White LED Module x 1<\/li>\n<li>OSOYOO 3-Pin PnP cable x 2<\/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<li>IRremote.h<\/li>\n<\/ul>\n<h1 id=\"3\">About the modules<\/h1>\n<p><img loading=\"lazy\" class=\"aligncenter size-large\" src=\"http:\/\/osoyoo.com\/picture\/Micro_bit_STEM\/Say_I_Love_You\/IR.png\" width=\"1000\" height=\"407\" \/><\/p>\n<h2><strong>What is IR?<\/strong><\/h2>\n<p>Infra-Red light is actually normal light with a particular colour. We humans can&#8217;t see this colour because its wave length of about 950nm is below the visible spectrum. That&#8217;s one of the reasons why IR is chosen for remote control purposes, we want to use it but we&#8217;re not interested in seeing it. Another reason is because IR LEDs are quite easy to make, and therefore can be very cheap, thus making it ideal for us hobbyists to use IR control for our own projects.<\/p>\n<p>We need to konw there are many more sources of Infra-Red light. The sun is the brightest source of all, but there are many others, like: light bulbs, candles, central heating system, and even our body radiates Infra-Red light.<\/p>\n<p>A common modulation scheme for IR communication is something called 38kHz modulation. There are very few natural sources that have the regularity of a 38kHz signal, so an IR transmitter sending data at that frequency would stand out among the ambient IR. 38kHz modulated IR data is the most common, but other frequencies can be used.<\/p>\n<p>When you hit a key on your remote, the transmitting IR LED will blink very quickly for a fraction of a second, transmitting encoded data to your appliance.<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/07\/FWZZ81DHHOFXIB2.MEDIUM.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-9266 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/07\/FWZZ81DHHOFXIB2.MEDIUM.jpg\" alt=\"\" width=\"620\" height=\"438\" \/><\/a><\/p>\n<p>If you were to hook an <a href=\"http:\/\/en.wikipedia.org\/wiki\/Oscilloscope\">oscilloscope<\/a> up to your TV remote\u2019s IR LED, you would see a signal similar to the one above. This modulated signal is exactly what the receiving system sees. However, the point of the receiving device is to demodulate the signal and output a binary waveform that can be read by a microcontroller. When you read the OUT pin of the VS1838B with the wave from above, you will see something like the second.<\/p>\n<h3 id=\"3.2\">Modulation<\/h3>\n<p>As everything that radiates heat, also radiates Infra-Red light. Therefore we have to take some precautions to guarantee that our IR message gets across to the receiver without errors.Modulation of the signal on a carrier frequency is the answer to make our signal stand out above the noise. With modulation we make the IR light source blink in a particular frequency. The IR receiver will be tuned to that frequency, so it can ignore everything else.<\/p>\n<p>In the picture below you can see a modulated signal driving the IR LED of the transmitter on the left side. The detected signal is coming out of the receiver at the other side.<\/p>\n<p><a href=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/07\/irsignal.gif\"><img loading=\"lazy\" class=\"size-full wp-image-9267 aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/07\/irsignal.gif\" alt=\"\" width=\"450\" height=\"120\" \/><\/a><\/p>\n<blockquote><p><em>(Thanks to <a href=\"http:\/\/www.sbprojects.com\/knowledge\/ir\/index.php\">SBProjects.com<\/a> for the gif and excellent IR resource!)<\/em><\/p><\/blockquote>\n<h2 id=\"3.5\">About the IR control<\/h2>\n<p><img loading=\"lazy\" class=\"aligncenter\" src=\"https:\/\/osoyoo.com\/wp-content\/uploads\/2017\/05\/18.jpg\" width=\"158\" height=\"158\" \/><\/p>\n<p>Infrared remotes are still the cheapest way to wirelessly control a device. We have designed the remote to be small, very simple, and low-cost.There are many different IR remote controls. all of these may have different encoding methods and number of physical buttons, and different codes received when a button is pressed.<\/p>\n<h2 id=\"3.6\">IR-REMOTE LIBRARY:<\/h2>\n<h4>Note: The following library <strong>must<\/strong> be installed in your Arduino installation for this to work!<\/h4>\n<p><a class=\"wiki_link_ext\" href=\"https:\/\/github.com\/shirriff\/Arduino-IRremote\" rel=\"nofollow\">CLICK HERE &#8211; IR REMOTE CONTROL: AR<\/a><a tabindex=\"-1\" href=\"https:\/\/github.com\/shirriff\/Arduino-IRremote\" target=\"_blank\" rel=\"noopener noreferrer\">github.com\/shirriff\/Arduino-IRremote<\/a><a class=\"wiki_link_ext\" href=\"https:\/\/github.com\/shirriff\/Arduino-IRremote\" rel=\"nofollow\">DUINO LIBRARY<\/a><\/p>\n<p>NOTE!! If you have a late version of Arduino with a library IRRobotRemote, it may conflict and you may have to remove that library.Make sure to delete Arduino(root)\/libraries\/RobotIRremote. Where Arduino(root) refers to the install directory of Arduino. The library RobotIRremote has similar definitions to IRremote and causes errors.<\/p>\n<h1 id=\"4\">Examples<\/h1>\n<h2 id=\"4.1\">Read codes from IR Remote<\/h2>\n<p>This example will show you how to read IR remote codes from any IR remote using the VS1838B IR receiver and an Arduino. Once you can receive codes from individual button presses, your remote control and Arduino become a general purpose, short range, communication interface!<\/p>\n<p>The first thing you need to do is make sure the <a href=\"https:\/\/github.com\/shirriff\/Arduino-IRremote\" target=\"_blank\" rel=\"noopener noreferrer\">IR Arduino library<\/a> has been installed, Instructions on how to install an Arduino library can be found <a href=\"https:\/\/osoyoo.com\/2020\/07\/29\/how-to-install-additional-arduino-libraries-2\/\">here<\/a>.<\/p>\n<h3 id=\"4.1.1\">Connection<\/h3>\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 IR Receiver module to the port D2 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\/Lesson21\/IR.jpg\" width=\"1000\" height=\"482\" \/><\/p>\n<h3 id=\"4.1.2\">Code Program<\/h3>\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=\"https:\/\/github.com\/osoyoo\/Osoyoo-development-kits\/tree\/master\/Osoyoo lessons for Arduino\/IR_basic.zip\" target=\"_blank\" rel=\"noopener noreferrer\">the following sketch<\/a> onto your Arduino.<\/p>\n<pre><span style=\"color: #5e6d03;\">#include<\/span> <span style=\"color: #434f54;\">&lt;<\/span><span style=\"color: #000000;\">IRremote<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">h<\/span><span style=\"color: #434f54;\">&gt;<\/span>  <span style=\"color: #434f54;\">\/\/ use the IRRemote.h<\/span>\r\n<span style=\"color: #00979c;\">const<\/span> <span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">irReceiverPin<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #000000;\">2<\/span><span style=\"color: #000000;\">;<\/span>  <span style=\"color: #434f54;\">\/\/the SIG of receiver module attach to pin2<\/span>\r\n<b><span style=\"color: #d35400;\">IRrecv<\/span><\/b> <span style=\"color: #000000;\">irrecv<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">irReceiverPin<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/Creates a variable of type IRrecv<\/span>\r\n<b><span style=\"color: #d35400;\">decode_results<\/span><\/b> <span style=\"color: #000000;\">results<\/span><span style=\"color: #000000;\">;<\/span>    <span style=\"color: #434f54;\">\/\/ define resultsas <\/span>\r\n\r\n<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;\">;<\/span>    <span style=\"color: #434f54;\">\/\/initialize serial,baudrate is 9600<\/span>\r\n  <span style=\"color: #000000;\">irrecv<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">enableIRIn<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>   <span style=\"color: #434f54;\">\/\/ enable ir receiver module<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\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  <span style=\"color: #5e6d03;\">if<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">irrecv<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">decode<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #434f54;\">&amp;<\/span><span style=\"color: #000000;\">results<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #434f54;\">\/\/if the ir receiver module receiver data<\/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;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\"irCode: \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>    <span style=\"color: #434f54;\">\/\/print \"irCode: \"        <\/span>\r\n    <b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">results<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">value<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #00979c;\">HEX<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/print the value in hexdecimal <\/span>\r\n    <b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\",  bits: \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>  <span style=\"color: #434f54;\">\/\/print\" , bits: \"         <\/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: #000000;\">results<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">bits<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/print the bits<\/span>\r\n    <span style=\"color: #000000;\">irrecv<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">resume<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>    <span style=\"color: #434f54;\">\/\/ Receive the next value <\/span>\r\n  <span style=\"color: #000000;\">}<\/span>  \r\n  <span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">600<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/delay 600ms<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n<\/pre>\n<p>When specific buttons are pressed, you can use the incoming values to do something else in your code, for example turn on and off a motor or LED.<\/p>\n<p>The results from each button press can be found by calling the value() method:<\/p>\n<blockquote>\n<pre><span style=\"color: #000000;\">results<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">value<\/span>\r\n<\/pre>\n<\/blockquote>\n<p>You can print the values to the Serial Monitor window:<\/p>\n<blockquote>\n<pre><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: #000000;\">results<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">value<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #00979c;\">HEX<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/prints the hex value a a button press<\/span>\r\n<\/pre>\n<\/blockquote>\n<h3 id=\"4.1.3\">Running Result<\/h3>\n<p>The sketch will automatically decode the type of remote you are using and identify which button on your remote is pressed. Open the Serial Monitor in the Arduino IDE at 9600 bps and hit different buttons on your remote. The Serial Monitor displaying random button presses on my remote. Different buttons show different codes:<\/p>\n<p><center><iframe src=\"https:\/\/www.youtube.com\/embed\/HFJWdODtj_A\" width=\"1280\" height=\"720\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/center>If you use the sketch above and count the 21 buttons from left to right and top to bottom, the codes received are these: (NOTE: Receiving &#8220;FFFFFFFF&#8221; means &#8220;repeat&#8221; if you hold the button down.)<\/p>\n<table class=\"wiki_table\">\n<tbody>\n<tr>\n<td>1<\/td>\n<td>FFA25D<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>FF629D<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>FFE21D<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>FF22DD<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>FF02FD<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>FFC23D<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>FFE01F<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>FFA857<\/td>\n<\/tr>\n<tr>\n<td>9<\/td>\n<td>FF906F<\/td>\n<\/tr>\n<tr>\n<td>10<\/td>\n<td>FF6897<\/td>\n<\/tr>\n<tr>\n<td>11<\/td>\n<td>FF9867<\/td>\n<\/tr>\n<tr>\n<td>12<\/td>\n<td>FFB04F<\/td>\n<\/tr>\n<tr>\n<td>13<\/td>\n<td>FF30CF<\/td>\n<\/tr>\n<tr>\n<td>14<\/td>\n<td>FF18E7<\/td>\n<\/tr>\n<tr>\n<td>15<\/td>\n<td>FF7A85<\/td>\n<\/tr>\n<tr>\n<td>16<\/td>\n<td>FF10EF<\/td>\n<\/tr>\n<tr>\n<td>17<\/td>\n<td>FF38C7<\/td>\n<\/tr>\n<tr>\n<td>18<\/td>\n<td>FF5AA5<\/td>\n<\/tr>\n<tr>\n<td>19<\/td>\n<td>FF42BD<\/td>\n<\/tr>\n<tr>\n<td>20<\/td>\n<td>FF4AB5<\/td>\n<\/tr>\n<tr>\n<td>21<\/td>\n<td>FF52AD<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"4.2\">IR Remote Test<\/h2>\n<p>When specific buttons are pressed, you can use the incoming values to do something else in your code, for example turn on and off a motor or LED.<\/p>\n<p>This example is to test the IR receiver, we modify the last sketch, when specific buttons are pressed, we will use the incoming values to print the corrseponding buttons&#8217; name of the IR control. The hardware connection is same as above example, before uplod the code, make sure you have installed the IRremote library!<\/p>\n<h3 id=\"4.2.1\">Code Program<\/h3>\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=\"https:\/\/github.com\/osoyoo\/Osoyoo-development-kits\/blob\/master\/Osoyoo%20lessons%20for%20Arduino\/IR_test.zip\">the following sketch<\/a> onto your Arduino.<\/p>\n<pre><span style=\"color: #5e6d03;\">#include<\/span> <span style=\"color: #005c5f;\">\"IRremote.h\"<\/span>\r\n<span style=\"color: #95a5a6;\">\/*-----( Declare Constants )-----*\/<\/span>\r\n<span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">receiver<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #000000;\">2<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ pin 1 of IR receiver to Arduino digital pin 2<\/span>\r\n<span style=\"color: #95a5a6;\">\/*-----( Declare objects )-----*\/<\/span>\r\n<b><span style=\"color: #d35400;\">IRrecv<\/span><\/b> <span style=\"color: #000000;\">irrecv<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">receiver<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>           <span style=\"color: #434f54;\">\/\/ create instance of 'irrecv'<\/span>\r\n<b><span style=\"color: #d35400;\">decode_results<\/span><\/b> <span style=\"color: #000000;\">results<\/span><span style=\"color: #000000;\">;<\/span>            <span style=\"color: #434f54;\">\/\/ create instance of 'decode_results'<\/span>\r\n<span style=\"color: #95a5a6;\">\/*-----( Declare Variables )-----*\/<\/span>\r\n\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: #95a5a6;\">\/*----( SETUP: RUNS ONCE )----*\/<\/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;\">;<\/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;\">\"IR Receiver Raw Data + Button Decode Test\"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #000000;\">irrecv<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">enableIRIn<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ Start the receiver<\/span>\r\n<span style=\"color: #000000;\">}<\/span><span style=\"color: #95a5a6;\">\/*--(end setup )---*\/<\/span>\r\n\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: #95a5a6;\">\/*----( LOOP: RUNS CONSTANTLY )----*\/<\/span>\r\n<span style=\"color: #000000;\">{<\/span>\r\n  <span style=\"color: #5e6d03;\">if<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">irrecv<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">decode<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #434f54;\">&amp;<\/span><span style=\"color: #000000;\">results<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #434f54;\">\/\/ have we received an IR signal?<\/span>\r\n  <span style=\"color: #000000;\">{<\/span>\r\n<span style=\"color: #434f54;\">\/\/    Serial.println(results.value, HEX);  UN Comment to see raw values<\/span>\r\n    <span style=\"color: #000000;\">translateIR<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #000000;\">irrecv<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">resume<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ receive the next value<\/span>\r\n  <span style=\"color: #000000;\">}<\/span>  \r\n<span style=\"color: #000000;\">}<\/span><span style=\"color: #95a5a6;\">\/* --(end main loop )-- *\/<\/span>\r\n\r\n<span style=\"color: #95a5a6;\">\/*-----( Declare User-written Functions )-----*\/<\/span>\r\n<span style=\"color: #00979c;\">void<\/span> <span style=\"color: #000000;\">translateIR<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #434f54;\">\/\/ takes action based on IR code received<\/span>\r\n<span style=\"color: #000000;\">{<\/span>\r\n  <span style=\"color: #5e6d03;\">switch<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">results<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">value<\/span><span style=\"color: #000000;\">)<\/span>\r\n  <span style=\"color: #000000;\">{<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFFA25D<\/span><span style=\"color: #434f54;\">:<\/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;\">\" CH-            \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF629D<\/span><span style=\"color: #434f54;\">:<\/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;\">\" CH             \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFFE21D<\/span><span style=\"color: #434f54;\">:<\/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;\">\" CH+            \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF22DD<\/span><span style=\"color: #434f54;\">:<\/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;\">\" PREV           \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF02FD<\/span><span style=\"color: #434f54;\">:<\/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;\">\" NEXT           \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFFC23D<\/span><span style=\"color: #434f54;\">:<\/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;\">\" PLAY\/PAUSE     \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFFE01F<\/span><span style=\"color: #434f54;\">:<\/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;\">\" VOL-           \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFFA857<\/span><span style=\"color: #434f54;\">:<\/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;\">\" VOL+           \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF906F<\/span><span style=\"color: #434f54;\">:<\/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;\">\" EQ             \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF6897<\/span><span style=\"color: #434f54;\">:<\/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;\">\" 0              \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF9867<\/span><span style=\"color: #434f54;\">:<\/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;\">\" 100+           \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFFB04F<\/span><span style=\"color: #434f54;\">:<\/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;\">\" 200+           \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF30CF<\/span><span style=\"color: #434f54;\">:<\/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;\">\" 1              \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF18E7<\/span><span style=\"color: #434f54;\">:<\/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;\">\" 2              \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF7A85<\/span><span style=\"color: #434f54;\">:<\/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;\">\" 3              \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF10EF<\/span><span style=\"color: #434f54;\">:<\/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;\">\" 4              \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF38C7<\/span><span style=\"color: #434f54;\">:<\/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;\">\" 5              \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF5AA5<\/span><span style=\"color: #434f54;\">:<\/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;\">\" 6              \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF42BD<\/span><span style=\"color: #434f54;\">:<\/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;\">\" 7              \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF4AB5<\/span><span style=\"color: #434f54;\">:<\/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;\">\" 8              \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">case<\/span> <span style=\"color: #000000;\">0xFF52AD<\/span><span style=\"color: #434f54;\">:<\/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;\">\" 9              \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> \r\n    <span style=\"color: #5e6d03;\">break<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #5e6d03;\">default<\/span><span style=\"color: #434f54;\">:<\/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;\">\" other button   \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span>\r\n  <span style=\"color: #000000;\">}<\/span>\r\n  <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<span style=\"color: #000000;\">}<\/span> <span style=\"color: #434f54;\">\/\/END translateIR<\/span>\r\n<\/pre>\n<h3 id=\"4.2.2\">Running Result<\/h3>\n<p>A few seconds after the upload finishes, hit different buttons on your remote, and open the serial port in the Arduino IDE at 9600 bps, you should see the software below displays the button that was pressed:<\/p>\n<p><center><iframe src=\"https:\/\/www.youtube.com\/embed\/3NX44_QSGt4\" width=\"1280\" height=\"720\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/center>Note: The Serial Monitor printing &#8220;other button&#8221; means the incoming values are not corresponding to your IR remote codes, it may appear if you hold the button down or there are other disturbances.<\/p>\n<h2 id=\"4.3\">IR Control LED<\/h2>\n<p>Control a certain key (for example, Power key) via a remote controller by programming. When you press the key, infrared rays will be emitted from the remote control and received by the infrared receiver, and the LED on the Osoyoo Uno board will light up. Connect an LED to pin 3 on the Osoyoo Uno board so that you can see remotely whether the Power key is pressed down.<\/p>\n<h3 id=\"4.3.1\">Connection<\/h3>\n<p>Connect the OSOYOO IR Receiver module to the port D2 of the Magic I\/O shield with 3-pin PNP cables, and connect the OSOYOO LED 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\/Lesson21\/IR+LED.jpg\" width=\"1000\" height=\"500\" \/><\/p>\n<h3 id=\"4.3.2\">Code Program<\/h3>\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. Load up <a href=\"https:\/\/github.com\/osoyoo\/Osoyoo-development-kits\/blob\/master\/Osoyoo%20lessons%20for%20Arduino\/IRcontrolLED.zip\" target=\"_blank\" rel=\"noopener noreferrer\">the following sketch<\/a> onto your Arduino.<\/p>\n<pre><span style=\"color: #5e6d03;\">#include<\/span> <span style=\"color: #434f54;\">&lt;<\/span><span style=\"color: #000000;\">IRremote<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">h<\/span><span style=\"color: #434f54;\">&gt;<\/span>\r\n<span style=\"color: #00979c;\">const<\/span> <span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">irReceiverPin<\/span> <span style=\"color: #434f54;\">=<\/span><span style=\"color: #000000;\">2<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/the SIG of receiver module attach to pin2 <\/span>\r\n<span style=\"color: #00979c;\">const<\/span> <span style=\"color: #00979c;\">int<\/span> <span style=\"color: #000000;\">ledPin<\/span> <span style=\"color: #434f54;\">=<\/span> <span style=\"color: #000000;\">3<\/span><span style=\"color: #000000;\">;<\/span><span style=\"color: #434f54;\">\/\/pin 3 connect to an led<\/span>\r\n<b><span style=\"color: #d35400;\">IRrecv<\/span><\/b> <span style=\"color: #000000;\">irrecv<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">irReceiverPin<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/Creates a variable of type IRrecv<\/span>\r\n<b><span style=\"color: #d35400;\">decode_results<\/span><\/b> <span style=\"color: #000000;\">results<\/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>\r\n<span style=\"color: #000000;\">{<\/span>\r\n  <span style=\"color: #d35400;\">pinMode<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">ledPin<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #00979c;\">OUTPUT<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span><span style=\"color: #434f54;\">\/\/set ledpin as OUTPUT<\/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;\">;<\/span><span style=\"color: #434f54;\">\/\/initialize serial <\/span>\r\n  <span style=\"color: #000000;\">irrecv<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">enableIRIn<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/enable ir receiver module <\/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  <span style=\"color: #5e6d03;\">if<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">irrecv<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">decode<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #434f54;\">&amp;<\/span><span style=\"color: #000000;\">results<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #434f54;\">\/\/if the ir receiver module receiver data<\/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;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\"irCode: \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/print\"irCode: \" <\/span>\r\n    <b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">results<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">value<\/span><span style=\"color: #434f54;\">,<\/span> <span style=\"color: #00979c;\">HEX<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/print the value in hexdecimal <\/span>\r\n    <b><span style=\"color: #d35400;\">Serial<\/span><\/b><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">print<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #005c5f;\">\", bits: \"<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/print\" , bits: \" <\/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: #000000;\">results<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">bits<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/print the bits<\/span>\r\n    <span style=\"color: #000000;\">irrecv<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #d35400;\">resume<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/ Receive the next value <\/span>\r\n  <span style=\"color: #000000;\">}<\/span> \r\n  <span style=\"color: #d35400;\">delay<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">600<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span> <span style=\"color: #434f54;\">\/\/delay 600ms<\/span>\r\n  <span style=\"color: #5e6d03;\">if<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">results<\/span><span style=\"color: #434f54;\">.<\/span><span style=\"color: #000000;\">value<\/span> <span style=\"color: #434f54;\">==<\/span> <span style=\"color: #000000;\">0xFFA25D<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #434f54;\">\/\/if receiver module receive 0xFFA25D<\/span>\r\n  <span style=\"color: #000000;\">{<\/span>\r\n    <span style=\"color: #d35400;\">digitalWrite<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">ledPin<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #00979c;\">HIGH<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span><span style=\"color: #434f54;\">\/\/turn on the led<\/span>\r\n  <span style=\"color: #000000;\">}<\/span>\r\n  <span style=\"color: #5e6d03;\">else<\/span>\r\n  <span style=\"color: #000000;\">{<\/span>\r\n    <span style=\"color: #d35400;\">digitalWrite<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #000000;\">ledPin<\/span><span style=\"color: #434f54;\">,<\/span><span style=\"color: #00979c;\">LOW<\/span><span style=\"color: #000000;\">)<\/span><span style=\"color: #000000;\">;<\/span><span style=\"color: #434f54;\">\/\/turn off the led<\/span>\r\n  <span style=\"color: #000000;\">}<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n<\/pre>\n<h3 id=\"4.3.3\">Running Result<\/h3>\n<p>A few seconds after the upload finishes, press the &#8220;CH-&#8221; button of a remote control, and both the LED attached and that connected to pin 3 on the Osoyoo Uno board will light up. Then press any other key, and the LEDs will go out.<\/p>\n<p><center><iframe src=\"https:\/\/www.youtube.com\/embed\/zXg2NEBf-FY\" width=\"1280\" height=\"720\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/center><a href=\"https:\/\/osoyoo.info\/index.php\/2020\/10\/12\/arduino-basic-lesson-19-servo\/\"><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-21-mini-fan\/\"><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":162,"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\/116"}],"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=116"}],"version-history":[{"count":2,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":122,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/posts\/116\/revisions\/122"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/media\/162"}],"wp:attachment":[{"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osoyoo.info\/index.php\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}