{"id":1226,"date":"2015-05-12T00:14:32","date_gmt":"2015-05-11T23:14:32","guid":{"rendered":"http:\/\/www.analysir.com\/blog\/?p=1226"},"modified":"2016-05-08T20:21:32","modified_gmt":"2016-05-08T19:21:32","slug":"simple-infrared-pwm-on-arduino","status":"publish","type":"post","link":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/","title":{"rendered":"Simple Infrared PWM on Arduino"},"content":{"rendered":"<p>We are often asked on discussion boards, about conflicts between IRremote or IRLib and other Arduino Libraries. In this post, we present a sketch for &#8216;Simple Infrared PWM on Arduino&#8217;. This is the first part in a 3 part series of posts. <strong>Part 1<\/strong> shows how to generate the Simple Infrared PWM on Arduino (AKA carrier frequency), using any available IO pin and without conflicting with other libraries. <strong><a href=\"https:\/\/www.analysir.com\/blog\/2015\/06\/10\/simple-infrared-pwm-on-arduino-part-2-raw-ir-signals\/\" target=\"_blank\">Part 2<\/a><\/strong> will show how to send a RAW infrared signal using this approach and <strong><a href=\"https:\/\/www.analysir.com\/blog\/2015\/09\/01\/simple-infrared-pwm-on-arduino-part-3-hex-ir-signals\/\" target=\"_blank\">Part 3<\/a><\/strong> will show how to send a common NEC signal from the binary or HEX value.<\/p>\n<figure id=\"attachment_1238\" aria-describedby=\"caption-attachment-1238\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/56khz-50-percent\/\" rel=\"attachment wp-att-1238\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1238\" src=\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/56kHz-50-percent.png\" alt=\"Example 56kHz generated Infrared signal @ 50% duty cycle\" width=\"550\" height=\"330\" srcset=\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/56kHz-50-percent.png 800w, https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/56kHz-50-percent-300x180.png 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-1238\" class=\"wp-caption-text\">Example 56 kHz generated Infrared signal @ 50% duty cycle<\/figcaption><\/figure>\n<p><!--more--><\/p>\n<blockquote><p>Simple Infrared PWM on Arduino<\/p><\/blockquote>\n<p>Next we consider the example sketch, by section:<\/p>\n<p><strong>Definitions<\/strong><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#define Duty_Cycle 56 \/\/in percent (10-&gt;50), usually 33 or 50\r\n\/\/TIP for true 50% use a value of 56, because of rounding errors\r\n\/\/TIP for true 40% use a value of 48, because of rounding errors\r\n\/\/TIP for true 33% use a value of 40, because of rounding errors\r\n\r\n#define Carrier_Frequency 56000 \/\/usually one of 38000, 40000, 36000, 56000, 33000, 30000\r\n\r\n#define PERIOD (1000000+Carrier_Frequency\/2)\/Carrier_Frequency\r\n#define HIGHTIME PERIOD*Duty_Cycle\/100\r\n#define LOWTIME PERIOD - HIGHTIME\r\n#define txPinIR 8 \/\/IR carrier output<\/pre>\n<p>First we configure the <strong>duty cycle<\/strong> for the Infrared carrier. Typically, values of 33% or 50% are used for IR, with 33% being popular in battery-powered systems. You will note our suggestions to use a value of 56 for 50% duty cycle and 40 for 33%, which is an artefact of rounding errors in the &#8216;#define&#8217; statements. In simple terms set Duty_Cycle to 56 for a 50% duty cycle. Next we define the carrier frequency. Almost all IR systems us a carrier frequency of either 38 kHz, 40 kHz, 36 kHz, 56 kHz, 33 kHz or 30 kHz. In addition, Bang + Olufsen systems use a carrier frequency of 455 kHz. However, this is very rare in use and is outside the scope of this sketch. The PERIOD is a simple calculation based on the defined carrier frequency. Similarly, HIGHTIME and LOWTIME are calculated automatically based on the period and the duty cycle. AS we mentioned before, you can select any Arduino pin for the IR output signal, including all digital and analogue pins.<\/p>\n<p><strong>Setup<\/strong><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">void setup() {\r\n\/* \r\n Serial.begin(9600); \/\/debug info\r\n while(!Serial);\r\n delay(500);\r\n Serial.println(PERIOD);\r\n Serial.println(HIGHTIME);\r\n Serial.println(LOWTIME);\r\n*\/\r\n\r\n pinMode(txPinIR,OUTPUT);\r\n}<\/pre>\n<p>As you can see from the setup function above, you only need to set the txPinIR to OUTPUT. The other code is purely for debugging to see the calculated values and can be uncommented as you wish.<\/p>\n<p><strong>Loop<\/strong><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">void loop() {\r\nfor (int i=0;i&lt;10;i++){\r\n mark(500);\r\n space(1000);\r\n}\r\ndelay(5000);\r\n}<\/pre>\n<p>For part 1, we demonstrate how to generate a basic Infrared signal using a for loop, mark, space and delay functions. This generates a signal every 5 seconds approximately. The signal consists of 10 pairs of mark and spaces. The marks are 500 microseconds long and the spaces are 1000 microseconds long (or 1 ms). In the following parts in this series we will see how to generate real world examples of Infrared signals. You can see an oscilloscope image of this signal above.<\/p>\n<p><strong>Mark<\/strong><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">void mark(unsigned long mLen) {\r\n if (mLen==0) return;\r\n unsigned long now = micros();\r\n while ((micros() - now) &lt; mLen) {\r\n digitalWrite(txPinIR, HIGH);\r\n delayMicroseconds(HIGHTIME-6);\r\n digitalWrite(txPinIR, LOW);\r\n delayMicroseconds(LOWTIME-7);\r\n }\r\n}<\/pre>\n<p><em>(At this point we suggest that you check out an <a href=\"http:\/\/www.sbprojects.com\/knowledge\/ir\/\" target=\"_blank\">excellent site<\/a> that explains the structure of IR signals, if you are not familiar with the concept of marks and spaces.) <\/em>The code in the mark function shown above simply toggles the txPinIR high and low very rapidly to create the carrier at the configured frequency and duty cycle. You will also notice the adjustments made (-6 -7) which are required because of the overhead in this code. In particular, digitalWrite is very (relatively) slow. An interesting feature of this mark function is that it can handle very long duration marks, unlike IRremote.<em><br \/>\n<\/em><\/p>\n<p><strong>Space<\/strong><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">void space(unsigned long sLen) {\r\n if (sLen==0) return;\r\n while (sLen&gt;16383) {\r\n delayMicroseconds(16383);\r\n sLen -= 16383;\r\n }\r\n delayMicroseconds(sLen);\r\n}<\/pre>\n<p>During a space the pin is held LOW, which is the default. Perhaps the simplest of all functions to implement! So in theory this function could be replaced with a delayMicroseconds function call. However, because of a designed limitation of delayMicroseconds on Arduino, it is not possible to delay for greater than 16,383 microseconds. This is particularly difficult for some IR signals for media devices and quite a few Air conditioner systems. We have implemented this function to check for zero and return immediately and handle situations where the duration is longer than the limit of delayMicroseconds, 16,383 uSecs. We have shown one approach to overcoming this limitation in the mark function above and an alternative approach in this space function.<\/p>\n<p><strong>Example Images<\/strong><\/p>\n<p>Below we present a selection of oscilloscope images, showing the various carrier frequencies and duty-cycles.<\/p>\n<p><strong>40kHZ<\/strong><\/p>\n<figure id=\"attachment_1237\" aria-describedby=\"caption-attachment-1237\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/40khz-50-per-cent\/\" rel=\"attachment wp-att-1237\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1237\" src=\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/40kHz-50-per-cent.png\" alt=\"40kHz Infrared carrier signal @ 50% duty cycle\" width=\"550\" height=\"330\" srcset=\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/40kHz-50-per-cent.png 800w, https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/40kHz-50-per-cent-300x180.png 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-1237\" class=\"wp-caption-text\">40kHz Infrared carrier signal @ 50% duty cycle<\/figcaption><\/figure>\n<p><strong>38kHz<\/strong><\/p>\n<figure id=\"attachment_1236\" aria-describedby=\"caption-attachment-1236\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/38khz-33-per-cent\/\" rel=\"attachment wp-att-1236\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1236\" src=\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/38kHz-33-per-cent.png\" alt=\"38kHz Infrared carrier signal @ 33% duty cycle\" width=\"550\" height=\"330\" srcset=\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/38kHz-33-per-cent.png 800w, https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/38kHz-33-per-cent-300x180.png 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-1236\" class=\"wp-caption-text\">38kHz Infrared carrier signal @ 33% duty cycle<\/figcaption><\/figure>\n<p><strong>36kHz<\/strong><\/p>\n<figure id=\"attachment_1235\" aria-describedby=\"caption-attachment-1235\" style=\"width: 552px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/36khz-50-percent\/\" rel=\"attachment wp-att-1235\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-1235\" src=\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/36kHz-50-percent.png\" alt=\"36kHz Infrared carrier signal @ 50% duty cycle\" width=\"552\" height=\"331\" srcset=\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/36kHz-50-percent.png 800w, https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/36kHz-50-percent-300x180.png 300w\" sizes=\"auto, (max-width: 552px) 100vw, 552px\" \/><\/a><figcaption id=\"caption-attachment-1235\" class=\"wp-caption-text\">36kHz Infrared carrier signal @ 50% duty cycle<\/figcaption><\/figure>\n<p><strong>Conclusion<\/strong><\/p>\n<p>Although not 100% accurate in terms of carrier frequency and duty cycle, we have shown an extremely effective method of generating Infrared signals on Arduino, without the use of timers. It also allows use of any IO pin and avoids conflicts with all Arduino libraries. It can also handle very long IR signal, unlike IRremote. Nice!<\/p>\n<p>Part 2 will show how to send a RAW Infrared signal and Part 3 will demonstrate how to send a standard NEC signal from its binary or HEX value.<\/p>\n<p>What about other MCU platforms? This same method will work on any platform, with only a few minor adjustments.<\/p>\n<p><strong>Part 2 in this series can be <a href=\"https:\/\/www.analysir.com\/blog\/2015\/06\/10\/simple-infrared-pwm-on-arduino-part-2-raw-ir-signals\/\" target=\"_blank\">found here.<\/a><br \/>\nPart 3 in this series can be <a href=\"https:\/\/www.analysir.com\/blog\/2015\/09\/01\/simple-infrared-pwm-on-arduino-part-3-hex-ir-signals\/\" target=\"_blank\">found here.<\/a><\/strong><\/p>\n<p style=\"text-align: center;\"><em>Please feel free to use the code in this blog post without restriction. If you gain any benefit please link back to this article credit the Author where possible.<\/em><\/p>\n<p style=\"text-align: right;\"><strong><a href=\"https:\/\/www.analysir.com\/blog\/get-analysir\/\" target=\"_blank\">Get your own copy of AnalysIR here.<\/a><\/strong><\/p>\n<blockquote><p>&nbsp;<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>We are often asked on discussion boards, about conflicts between IRremote or IRLib and other Arduino Libraries. In this post, we present a sketch for &#8216;Simple Infrared PWM on Arduino&#8217;. This is the first part in a 3 part series of posts. Part 1 shows how to generate the Simple Infrared PWM on Arduino (AKA &hellip; <a href=\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Simple Infrared PWM on Arduino<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1,10],"tags":[197,272,29,7,33,97,6,5,273],"class_list":["post-1226","post","type-post","status-publish","format-standard","hentry","category-analysir-blog","category-arduino","tag-air-conditioner","tag-carrier-frequency","tag-decoding","tag-infrared","tag-ir","tag-ir-signals","tag-irlib","tag-irremote","tag-pwm"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Simple Infrared PWM on Arduino - AnalysIR Blog<\/title>\n<meta name=\"description\" content=\"In this post, we present a sketch for Simple Infrared PWM on Arduino. This is the first part in a 3 part series of posts covering variations in this topic.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Simple Infrared PWM on Arduino - AnalysIR Blog\" \/>\n<meta property=\"og:description\" content=\"In this post, we present a sketch for Simple Infrared PWM on Arduino. This is the first part in a 3 part series of posts covering variations in this topic.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/\" \/>\n<meta property=\"og:site_name\" content=\"AnalysIR Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/chris.analysir\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/chris.analysir\" \/>\n<meta property=\"article:published_time\" content=\"2015-05-11T23:14:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-05-08T19:21:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/56kHz-50-percent.png\" \/>\n<meta name=\"author\" content=\"User Two\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@AnalysIR\" \/>\n<meta name=\"twitter:site\" content=\"@analysir\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"User Two\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/\"},\"author\":{\"name\":\"User Two\",\"@id\":\"https:\/\/www.analysir.com\/blog\/#\/schema\/person\/16a6d94c57d4f2629096ab80a7b36e13\"},\"headline\":\"Simple Infrared PWM on Arduino\",\"datePublished\":\"2015-05-11T23:14:32+00:00\",\"dateModified\":\"2016-05-08T19:21:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/\"},\"wordCount\":1007,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/www.analysir.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/56kHz-50-percent.png\",\"keywords\":[\"Air Conditioner\",\"Carrier frequency\",\"decoding\",\"Infrared\",\"IR\",\"IR signals\",\"IRLib\",\"IRremote\",\"pwm\"],\"articleSection\":[\"AnalysIR Blog\",\"Arduino\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/\",\"url\":\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/\",\"name\":\"Simple Infrared PWM on Arduino - AnalysIR Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.analysir.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/56kHz-50-percent.png\",\"datePublished\":\"2015-05-11T23:14:32+00:00\",\"dateModified\":\"2016-05-08T19:21:32+00:00\",\"description\":\"In this post, we present a sketch for Simple Infrared PWM on Arduino. This is the first part in a 3 part series of posts covering variations in this topic.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#primaryimage\",\"url\":\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/56kHz-50-percent.png\",\"contentUrl\":\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/56kHz-50-percent.png\",\"width\":800,\"height\":480,\"caption\":\"Example 56kHz generated Infrared signal @ 50% duty cycle\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.analysir.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Simple Infrared PWM on Arduino\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.analysir.com\/blog\/#website\",\"url\":\"https:\/\/www.analysir.com\/blog\/\",\"name\":\"AnalysIR Blog\",\"description\":\"All about infrared remote control, IR decoding and more\",\"publisher\":{\"@id\":\"https:\/\/www.analysir.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.analysir.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.analysir.com\/blog\/#organization\",\"name\":\"AnalysIR\",\"url\":\"https:\/\/www.analysir.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.analysir.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/10\/AnalysIR_and_IRToy.png\",\"contentUrl\":\"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/10\/AnalysIR_and_IRToy.png\",\"width\":200,\"height\":200,\"caption\":\"AnalysIR\"},\"image\":{\"@id\":\"https:\/\/www.analysir.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/chris.analysir\",\"https:\/\/x.com\/analysir\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.analysir.com\/blog\/#\/schema\/person\/16a6d94c57d4f2629096ab80a7b36e13\",\"name\":\"User Two\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/8167f41ca01c8bf0646f87048aaf9e8f90e7d0b65650c0f8eaaf8002b288d6cb?s=96&d=identicon&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8167f41ca01c8bf0646f87048aaf9e8f90e7d0b65650c0f8eaaf8002b288d6cb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8167f41ca01c8bf0646f87048aaf9e8f90e7d0b65650c0f8eaaf8002b288d6cb?s=96&d=identicon&r=g\",\"caption\":\"User Two\"},\"sameAs\":[\"http:\/\/www.AnalysIR.com\",\"https:\/\/www.facebook.com\/chris.analysir\",\"https:\/\/x.com\/AnalysIR\"],\"url\":\"https:\/\/www.analysir.com\/blog\/author\/analysir\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Simple Infrared PWM on Arduino - AnalysIR Blog","description":"In this post, we present a sketch for Simple Infrared PWM on Arduino. This is the first part in a 3 part series of posts covering variations in this topic.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/","og_locale":"en_US","og_type":"article","og_title":"Simple Infrared PWM on Arduino - AnalysIR Blog","og_description":"In this post, we present a sketch for Simple Infrared PWM on Arduino. This is the first part in a 3 part series of posts covering variations in this topic.","og_url":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/","og_site_name":"AnalysIR Blog","article_publisher":"https:\/\/www.facebook.com\/chris.analysir","article_author":"https:\/\/www.facebook.com\/chris.analysir","article_published_time":"2015-05-11T23:14:32+00:00","article_modified_time":"2016-05-08T19:21:32+00:00","og_image":[{"url":"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/56kHz-50-percent.png","type":"","width":"","height":""}],"author":"User Two","twitter_card":"summary_large_image","twitter_creator":"@AnalysIR","twitter_site":"@analysir","twitter_misc":{"Written by":"User Two","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#article","isPartOf":{"@id":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/"},"author":{"name":"User Two","@id":"https:\/\/www.analysir.com\/blog\/#\/schema\/person\/16a6d94c57d4f2629096ab80a7b36e13"},"headline":"Simple Infrared PWM on Arduino","datePublished":"2015-05-11T23:14:32+00:00","dateModified":"2016-05-08T19:21:32+00:00","mainEntityOfPage":{"@id":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/"},"wordCount":1007,"commentCount":2,"publisher":{"@id":"https:\/\/www.analysir.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#primaryimage"},"thumbnailUrl":"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/56kHz-50-percent.png","keywords":["Air Conditioner","Carrier frequency","decoding","Infrared","IR","IR signals","IRLib","IRremote","pwm"],"articleSection":["AnalysIR Blog","Arduino"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/","url":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/","name":"Simple Infrared PWM on Arduino - AnalysIR Blog","isPartOf":{"@id":"https:\/\/www.analysir.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#primaryimage"},"image":{"@id":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#primaryimage"},"thumbnailUrl":"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/56kHz-50-percent.png","datePublished":"2015-05-11T23:14:32+00:00","dateModified":"2016-05-08T19:21:32+00:00","description":"In this post, we present a sketch for Simple Infrared PWM on Arduino. This is the first part in a 3 part series of posts covering variations in this topic.","breadcrumb":{"@id":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#primaryimage","url":"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/56kHz-50-percent.png","contentUrl":"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/05\/56kHz-50-percent.png","width":800,"height":480,"caption":"Example 56kHz generated Infrared signal @ 50% duty cycle"},{"@type":"BreadcrumbList","@id":"https:\/\/www.analysir.com\/blog\/2015\/05\/12\/simple-infrared-pwm-on-arduino\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.analysir.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Simple Infrared PWM on Arduino"}]},{"@type":"WebSite","@id":"https:\/\/www.analysir.com\/blog\/#website","url":"https:\/\/www.analysir.com\/blog\/","name":"AnalysIR Blog","description":"All about infrared remote control, IR decoding and more","publisher":{"@id":"https:\/\/www.analysir.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.analysir.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.analysir.com\/blog\/#organization","name":"AnalysIR","url":"https:\/\/www.analysir.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.analysir.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/10\/AnalysIR_and_IRToy.png","contentUrl":"https:\/\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/10\/AnalysIR_and_IRToy.png","width":200,"height":200,"caption":"AnalysIR"},"image":{"@id":"https:\/\/www.analysir.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/chris.analysir","https:\/\/x.com\/analysir"]},{"@type":"Person","@id":"https:\/\/www.analysir.com\/blog\/#\/schema\/person\/16a6d94c57d4f2629096ab80a7b36e13","name":"User Two","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/8167f41ca01c8bf0646f87048aaf9e8f90e7d0b65650c0f8eaaf8002b288d6cb?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8167f41ca01c8bf0646f87048aaf9e8f90e7d0b65650c0f8eaaf8002b288d6cb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8167f41ca01c8bf0646f87048aaf9e8f90e7d0b65650c0f8eaaf8002b288d6cb?s=96&d=identicon&r=g","caption":"User Two"},"sameAs":["http:\/\/www.AnalysIR.com","https:\/\/www.facebook.com\/chris.analysir","https:\/\/x.com\/AnalysIR"],"url":"https:\/\/www.analysir.com\/blog\/author\/analysir\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p42zhM-jM","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1682,"url":"https:\/\/www.analysir.com\/blog\/2015\/10\/12\/backdoor-upwm-hack-on-arduino-for-infrared-signals-using-uart\/","url_meta":{"origin":1226,"position":0},"title":"Backdoor uPWM Hack on Arduino for Infrared signals using UART","author":"User Two","date":"October 12, 2015","format":false,"excerpt":"In this blog post we follow up on our recent article about generation of infrared PWM from the Photon's UART where we suggested that it may be possible to achieve something similar with the Arduino. In our previous attempt the Arduino was only able to generate PWM at 40 kHz\u2026","rel":"","context":"In &quot;AnalysIR Blog&quot;","block_context":{"text":"AnalysIR Blog","link":"https:\/\/www.analysir.com\/blog\/analysir-blog\/"},"img":{"alt_text":"Arduino uPWM Circuit Diagram","src":"https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/10\/Arduino-uPWM-Circuit.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/10\/Arduino-uPWM-Circuit.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/10\/Arduino-uPWM-Circuit.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1638,"url":"https:\/\/www.analysir.com\/blog\/2015\/10\/02\/backdoor-upwm-hack-on-photon-for-infrared-signals-using-uart\/","url_meta":{"origin":1226,"position":1},"title":"Backdoor uPWM Hack on Photon for Infrared signals using UART","author":"User Two","date":"October 2, 2015","format":false,"excerpt":"Since we received our Photon several months ago it has been difficult to find a working example of Hardware PWM on the Photon. Initially, we ported our softPWM approach to the Photon, which is excellent. However, we figured it must be possible to use at least one of the spare\u2026","rel":"","context":"In &quot;AnalysIR Blog&quot;","block_context":{"text":"AnalysIR Blog","link":"https:\/\/www.analysir.com\/blog\/analysir-blog\/"},"img":{"alt_text":"uPWM Circuit diagram for Photon","src":"https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/10\/uPWM-Photon-Circuit.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/10\/uPWM-Photon-Circuit.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/10\/uPWM-Photon-Circuit.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2015\/10\/uPWM-Photon-Circuit.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":2560,"url":"https:\/\/www.analysir.com\/blog\/2016\/07\/06\/esp8266-nodemcu-backdoor-upwm-hack-ir-signals-using-uart\/","url_meta":{"origin":1226,"position":2},"title":"ESP8266 NodeMCU Backdoor uPWM Hack for IR signals","author":"User Two","date":"July 6, 2016","format":false,"excerpt":"We received our ESP8266 NodeMCU several months ago it has been difficult to find a working example of Hardware PWM to generate crisp Infrared carrier signals. Most posts we have read suggest that there is no PWM readily available on any of the supported platforms. As we have already shown\u2026","rel":"","context":"In &quot;AnalysIR Blog&quot;","block_context":{"text":"AnalysIR Blog","link":"https:\/\/www.analysir.com\/blog\/analysir-blog\/"},"img":{"alt_text":"ESP8266 NodeMCU uPWM NEC IR Signal","src":"https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2016\/07\/ESP8266-NodeMCU-uPWM-NEC-IR-Signal.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2016\/07\/ESP8266-NodeMCU-uPWM-NEC-IR-Signal.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2016\/07\/ESP8266-NodeMCU-uPWM-NEC-IR-Signal.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2016\/07\/ESP8266-NodeMCU-uPWM-NEC-IR-Signal.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":455,"url":"https:\/\/www.analysir.com\/blog\/2014\/03\/05\/arduino-10-common-pitfalls-infrared-remote-control\/","url_meta":{"origin":1226,"position":3},"title":"Arduino: 10 common pitfalls with Infrared Remote Control","author":"User Two","date":"March 5, 2014","format":false,"excerpt":"Over the last few months we have been regular contributors to the Arduino and other forums, answering questions about Infrared remote control projects. It became apparent that beginners typically trip up on many common 'pitfalls'. So we decided to list off our 'Top 10'. \u00a0 (Note a PDF of this\u2026","rel":"","context":"In &quot;AnalysIR Blog&quot;","block_context":{"text":"AnalysIR Blog","link":"https:\/\/www.analysir.com\/blog\/analysir-blog\/"},"img":{"alt_text":"Arduino: 10 common pitfalls with Infrared Remote Control","src":"https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2014\/03\/VideoThumbnail-300x168.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1996,"url":"https:\/\/www.analysir.com\/blog\/2016\/01\/14\/esp8266-nodemcu-infrared-decoding-added-to-analysir\/","url_meta":{"origin":1226,"position":4},"title":"ESP8266 NodeMCU Infrared decoding added to AnalysIR","author":"User Two","date":"January 14, 2016","format":false,"excerpt":"A few months ago a new user to AnalysIR, from Canada, asked us to assist in adding ESP8266 NodeMCU Infrared decoding over WiFi into\u00a0 AnalysIR. We set about making some upgrades to AnalysIR for this and in double quick time he had AnalysIR accepting IR signals from the ESP8266 over\u2026","rel":"","context":"In &quot;AnalysIR Blog&quot;","block_context":{"text":"AnalysIR Blog","link":"https:\/\/www.analysir.com\/blog\/analysir-blog\/"},"img":{"alt_text":"AnalysIR supports ESP82266 NodeMCU","src":"https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2016\/01\/NodeMCU.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2016\/01\/NodeMCU.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2016\/01\/NodeMCU.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":640,"url":"https:\/\/www.analysir.com\/blog\/2014\/07\/06\/controlling-chigo-air-conditioner-via-infrared-smart-phone\/","url_meta":{"origin":1226,"position":5},"title":"Controlling Chigo Air Conditioner via Infrared from smart phone","author":"User Two","date":"July 6, 2014","format":false,"excerpt":"Anyone who has tried\u00a0 controlling an Air Conditioner unit using an Arduino, USB IR Toy, RPi or any MCU will know how difficult it can be to record the longer infrared signals they use. Typical TV systems use IR signals circa 32 bits long, while this Chigo AC unit uses\u2026","rel":"","context":"In &quot;AnalysIR Blog&quot;","block_context":{"text":"AnalysIR Blog","link":"https:\/\/www.analysir.com\/blog\/analysir-blog\/"},"img":{"alt_text":"Samsung IR Remote app","src":"https:\/\/i0.wp.com\/www.analysir.com\/blog\/wp-content\/uploads\/2014\/07\/SamsungIRremote0-168x300.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.analysir.com\/blog\/wp-json\/wp\/v2\/posts\/1226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.analysir.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.analysir.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.analysir.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.analysir.com\/blog\/wp-json\/wp\/v2\/comments?post=1226"}],"version-history":[{"count":10,"href":"https:\/\/www.analysir.com\/blog\/wp-json\/wp\/v2\/posts\/1226\/revisions"}],"predecessor-version":[{"id":2393,"href":"https:\/\/www.analysir.com\/blog\/wp-json\/wp\/v2\/posts\/1226\/revisions\/2393"}],"wp:attachment":[{"href":"https:\/\/www.analysir.com\/blog\/wp-json\/wp\/v2\/media?parent=1226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.analysir.com\/blog\/wp-json\/wp\/v2\/categories?post=1226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.analysir.com\/blog\/wp-json\/wp\/v2\/tags?post=1226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}