<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Electronics on Diarmuid.ie</title><link>/tags/electronics/</link><description>Recent content in Electronics on Diarmuid.ie</description><generator>Hugo -- 0.164.0</generator><language>en-IE</language><lastBuildDate>Mon, 16 Dec 2013 00:00:00 +0000</lastBuildDate><atom:link href="/tags/electronics/feed.xml" rel="self" type="application/rss+xml"/><item><title>PWM Exponential LED Fading on Arduino (or other platforms)</title><link>/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/</link><pubDate>Mon, 16 Dec 2013 00:00:00 +0000</pubDate><guid>/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/</guid><description>&lt;p&gt;For a project I am working on I needed to dim a LED strip light using the PWM (pulse width modulated) outputs on an Arduino. The most straightforward way to do this would have been to linearly vary the output frequency. Shown below in an Arduino sketch:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-c++" data-lang="c++"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Use pin 9 as the PWM output
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;const&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; outputPin &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;9&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;setup&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// Set the pin as a digital output
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; pinMode(outputPin, OUTPUT);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;loop&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// Fade the brightness from 0 (min) to 255 (max) with 40ms delay per step
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; (&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; brightness &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;; brightness &lt;span style="color:#f92672"&gt;&amp;lt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;255&lt;/span&gt;; brightness&lt;span style="color:#f92672"&gt;++&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; analogWrite(outputPin, brightness);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; delay(&lt;span style="color:#ae81ff"&gt;40&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;However the light outputted by the LED does not scale linearly. If you were to use the very scientific metric of &amp;ldquo;Perceived Brightness&amp;rdquo; vs. time for the above sketch it would look something like the below for a linear PWM signal:&lt;/p&gt;
&lt;p&gt;
&lt;figure&gt;
&lt;picture&gt;
&lt;source type="image/webp" srcset="https://diarmuid.ie/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/brightness-vs-time-linear_hu_52cf05a2cd9b1ec5.webp 360w,/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/brightness-vs-time-linear_hu_1c14d5a682587e49.webp 480w,/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/brightness-vs-time-linear_hu_aaf0437f02009d9c.webp 720w" /&gt;
&lt;source type="image/png" srcset="https://diarmuid.ie/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/brightness-vs-time-linear_hu_24a770e31710c192.png 360w,/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/brightness-vs-time-linear_hu_5c3843be91a807c9.png 480w,/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/brightness-vs-time-linear_hu_4227298a6a0ba836.png 720w" /&gt;
&lt;img
src="https://diarmuid.ie/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/brightness-vs-time-linear_hu_4227298a6a0ba836.png"
width="720"
height="623"
alt="brightness_vs_time_linear"
/&gt;
&lt;/picture&gt;
&lt;/figure&gt;
&lt;/p&gt;</description></item><item><title>Experiences with Buying Cheap Arduinos and shields on eBay</title><link>/blog/experiences-with-buying-cheap-arduinos-and-shields-on-ebay/</link><pubDate>Mon, 04 Jun 2012 00:00:00 +0000</pubDate><guid>/blog/experiences-with-buying-cheap-arduinos-and-shields-on-ebay/</guid><description>&lt;p&gt;Recently I&amp;rsquo;ve started getting interested in electronics and in particular &lt;a href="http://arduino.cc/"&gt;Arduino&lt;/a&gt;. Ardunios are a microcontroller boards that you can programme to perform actions. The board I am interested in is the entry level &lt;a href="http://arduino.cc/en/Main/ArduinoBoardUno"&gt;Ardunio Uno&lt;/a&gt;. This board has 14 digital inputs/outputs and 6 analogue inputs. The Arduino can be expanded with Shields, these are addon boards that stack on top of the Arduino to offer additional functionality (like ethernet, storage, motors etc.)&lt;/p&gt;
&lt;p&gt;Buying genuine Arduinos in Ireland can be costly because they have to be ordered from suppliers in the &lt;a href="http://www.sparkfun.com/products/11021"&gt;US&lt;/a&gt; or &lt;a href="http://uk.farnell.com/arduino"&gt;UK&lt;/a&gt;/&lt;a href="http://store.arduino.cc/eu/index.php?main_page=product_info&amp;amp;cPath=11_12&amp;amp;products_id=195"&gt;Europe&lt;/a&gt;. Often the cost of shipping and customs exceeds the cost of the Arduino itself!&lt;/p&gt;</description></item></channel></rss>