{"id":5782,"date":"2023-07-01T12:01:47","date_gmt":"2023-07-01T10:01:47","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=5782"},"modified":"2024-05-16T16:59:33","modified_gmt":"2024-05-16T14:59:33","slug":"under-the-hood-arduino-uno-r4-pwm","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/","title":{"rendered":"Under the Hood: Arduino UNO R4 &#8211; PWM"},"content":{"rendered":"<p>In Arduino we can use the <strong>analogWrite(pin, value)<\/strong> method to create a <strong>PWM signal<\/strong> on the digital pins. The value parameter is used to change the duty cycle but the PWM frequency which is fixed at usually 490 Hz and can not be changed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/06\/UnoR4.jpg\" alt=\"\" width=\"300\" height=\"300\" class=\"alignnone size-full wp-image-5728\" srcset=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/06\/UnoR4.jpg 300w, https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/06\/UnoR4-150x150.jpg 150w, https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/06\/UnoR4-120x120.jpg 120w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Here is a simple example sketch that also works with the UNO R4:<\/p>\n<pre><code>void setup() {\n  pinMode(D2, OUTPUT);\n  \/\/ set 100%\n  analogWrite(D2,255) \n}\n\nvoid loop() {}\n<\/code><\/pre>\n<p>Fortunately the <strong>Arduino UNO R4<\/strong> provides some easy to use <strong>PwmOut class<\/strong> which provides more flexibility: You define the frequncy in hz and the initial duty percent. There is also a method to update the <strong>duty cycle using percent<\/strong>.<\/p>\n<pre><code>#include \"pwm.h\"\n\nPwmOut pwm(D2);\n\nvoid setup() {\n  \/\/period 50us = 20000hz; pulse 0 us = 0%\n  pwm.begin(20000.0f, 0.0f);\n\n  \/\/ set 100%\n  pwm.pulse_perc(100.0f);\n\n}\n\nvoid loop() {}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In Arduino we can use the analogWrite(pin, value) method to create a PWM signal on the digital pins. The value parameter is used to change the duty cycle but the PWM frequency which is fixed at usually 490 Hz and can not be changed. Here is a simple example sketch [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5728,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[20],"tags":[44],"class_list":["post-5782","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","tag-uno"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Under the Hood: Arduino UNO R4 - PWM - Phil Schatzmann<\/title>\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.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Under the Hood: Arduino UNO R4 - PWM - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"In Arduino we can use the analogWrite(pin, value) method to create a PWM signal on the digital pins. The value parameter is used to change the duty cycle but the PWM frequency which is fixed at usually 490 Hz and can not be changed. Here is a simple example sketch [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-01T10:01:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-16T14:59:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/06\/UnoR4.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"pschatzmann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"pschatzmann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/07\\\/01\\\/under-the-hood-arduino-uno-r4-pwm\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/07\\\/01\\\/under-the-hood-arduino-uno-r4-pwm\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"Under the Hood: Arduino UNO R4 &#8211; PWM\",\"datePublished\":\"2023-07-01T10:01:47+00:00\",\"dateModified\":\"2024-05-16T14:59:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/07\\\/01\\\/under-the-hood-arduino-uno-r4-pwm\\\/\"},\"wordCount\":104,\"commentCount\":17,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/07\\\/01\\\/under-the-hood-arduino-uno-r4-pwm\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/UnoR4.jpg\",\"keywords\":[\"UNO\"],\"articleSection\":[\"Arduino\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/07\\\/01\\\/under-the-hood-arduino-uno-r4-pwm\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/07\\\/01\\\/under-the-hood-arduino-uno-r4-pwm\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/07\\\/01\\\/under-the-hood-arduino-uno-r4-pwm\\\/\",\"name\":\"Under the Hood: Arduino UNO R4 - PWM - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/07\\\/01\\\/under-the-hood-arduino-uno-r4-pwm\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/07\\\/01\\\/under-the-hood-arduino-uno-r4-pwm\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/UnoR4.jpg\",\"datePublished\":\"2023-07-01T10:01:47+00:00\",\"dateModified\":\"2024-05-16T14:59:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/07\\\/01\\\/under-the-hood-arduino-uno-r4-pwm\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/07\\\/01\\\/under-the-hood-arduino-uno-r4-pwm\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/07\\\/01\\\/under-the-hood-arduino-uno-r4-pwm\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/UnoR4.jpg\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/UnoR4.jpg\",\"width\":300,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/07\\\/01\\\/under-the-hood-arduino-uno-r4-pwm\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Under the Hood: Arduino UNO R4 &#8211; PWM\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\",\"name\":\"Phil Schatzmann Consulting\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\",\"name\":\"pschatzmann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"width\":305,\"height\":305,\"caption\":\"pschatzmann\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Under the Hood: Arduino UNO R4 - PWM - Phil Schatzmann","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.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/","og_locale":"en_US","og_type":"article","og_title":"Under the Hood: Arduino UNO R4 - PWM - Phil Schatzmann","og_description":"In Arduino we can use the analogWrite(pin, value) method to create a PWM signal on the digital pins. The value parameter is used to change the duty cycle but the PWM frequency which is fixed at usually 490 Hz and can not be changed. Here is a simple example sketch [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/","og_site_name":"Phil Schatzmann","article_published_time":"2023-07-01T10:01:47+00:00","article_modified_time":"2024-05-16T14:59:33+00:00","og_image":[{"width":300,"height":300,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/06\/UnoR4.jpg","type":"image\/jpeg"}],"author":"pschatzmann","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pschatzmann","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"Under the Hood: Arduino UNO R4 &#8211; PWM","datePublished":"2023-07-01T10:01:47+00:00","dateModified":"2024-05-16T14:59:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/"},"wordCount":104,"commentCount":17,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/06\/UnoR4.jpg","keywords":["UNO"],"articleSection":["Arduino"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/","url":"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/","name":"Under the Hood: Arduino UNO R4 - PWM - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/06\/UnoR4.jpg","datePublished":"2023-07-01T10:01:47+00:00","dateModified":"2024-05-16T14:59:33+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/06\/UnoR4.jpg","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/06\/UnoR4.jpg","width":300,"height":300},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/07\/01\/under-the-hood-arduino-uno-r4-pwm\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"Under the Hood: Arduino UNO R4 &#8211; PWM"}]},{"@type":"WebSite","@id":"https:\/\/www.pschatzmann.ch\/home\/#website","url":"https:\/\/www.pschatzmann.ch\/home\/","name":"Phil Schatzmann Consulting","description":"","publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pschatzmann.ch\/home\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1","name":"pschatzmann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","width":305,"height":305,"caption":"pschatzmann"},"logo":{"@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png"}}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/comments?post=5782"}],"version-history":[{"count":7,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5782\/revisions"}],"predecessor-version":[{"id":6260,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5782\/revisions\/6260"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/5728"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=5782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=5782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=5782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}