{"id":6292,"date":"2012-12-19T21:34:24","date_gmt":"2012-12-20T02:34:24","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=6292"},"modified":"2013-05-18T12:05:40","modified_gmt":"2013-05-18T16:05:40","slug":"day-1-flashing-an-led-with-potentiometer","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/day-1-flashing-an-led-with-potentiometer\/","title":{"rendered":"Netduino Day 1: Basic Input and Output"},"content":{"rendered":"<p>We will start our Netduino tutorial series with a very basic project of flashing an LED. The objective of this project is to explore basics of Netduino I\/O pins as well as to make sure that everything is setup correctly, including software installation and hardware setup.\u00a0In this project, we will use an Analog pin to read a potentiometer&#8217;s analog output, and a digital pin to flash an LED. The frequency of LED blinking is varied based on the potentiometer output. It will blink at an interval of 10 milliseconds to 1000 milliseconds based on the wiper position of the potentiometer. In Netduino, you can set the range for 10-bit ADC output of an analog port.Writing code will be carried out in Visual Studio with C# as programming language.<\/p>\n<div id=\"attachment_6480\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=6480\" rel=\"attachment wp-att-6480\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6480\" class=\"size-full wp-image-6480\" title=\"Netduino based Flashing LED \" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/11\/Day1_FlashingLED_Breadboard.png\" alt=\"\" width=\"550\" height=\"414\" \/><\/a><p id=\"caption-attachment-6480\" class=\"wp-caption-text\">Netduino based Flashing LED<\/p><\/div>\n<p><!--more--><\/p>\n<p>If you are not sure where to write a code or how to connect your Netduino (or Netduino Plus) to your computer then please go through\u00a0<a href=\"http:\/\/embedded-lab.com\/blog\/?p=6206\" target=\"_blank\">Getting Ready for Netduino \/ Netduino Plus Tutorials<\/a><\/p>\n<h2>Circuit Setup and Theory<\/h2>\n<div id=\"attachment_6481\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=6481\" rel=\"attachment wp-att-6481\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6481\" class=\"size-full wp-image-6481\" title=\"Flashing LED with Potentiometer Circuit Diagram\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/11\/Day1_FlashingLED_Circuit_Diagram.png\" alt=\"\" width=\"550\" height=\"410\" \/><\/a><p id=\"caption-attachment-6481\" class=\"wp-caption-text\">Flashing LED with Potentiometer Circuit Diagram<\/p><\/div>\n<p>We can split the experiment into two parts, first around analog input, which is around the potentiometer and second around the digital I\/O i.e. around transistor and LED. In the analog section, we simply connected two end-leads of potentiometer to the ground and 3v3 and the middle lead to the A1 port of the Netduino. In our code, we have defined the range of this analog device from 10 milliseconds to 1000 millisecond. So, when the pot is rotated (its resistance is changed) , microcontroller will feed us a value between given range accordingly. Guess what? We converted our analog signal to digital signal! Potentiometer is an analog device and we ranged it\u2019s value from 10 milliseconds to 1 second.<\/p>\n<p>In the second half of the connection, the D1 (Digital I\/O) of Netduino is connected to the base of a transistor along with a resistor. This transistor is used as a switch in the circuit. When we set the D1 port to high, transistor will reach its saturation state and hence current starts flowing along Base and Collector. The moment this happens, our LED will turn ON, because a complete circuit is formed from 5v to the ground. Accordingly, when D1 port is low, no current will flow through the Base and Collector causing an incomplete circuit from 5v to the ground. Hence LED will turn Off.<\/p>\n<h2>Connection With Netduino \/ Netduino Plus<\/h2>\n<div id=\"attachment_6295\" style=\"width: 451px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=6295\" rel=\"attachment wp-att-6295\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6295\" class=\"size-full wp-image-6295 \" title=\"Connections with Netduino: Flashing LED\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/11\/Day1_FlashingLEDwithPot_Flitizing.png\" alt=\"Flashing LED Breadboard Connecion\" width=\"441\" height=\"467\" \/><\/a><p id=\"caption-attachment-6295\" class=\"wp-caption-text\">Connection with Netduino: Flashing LED with Potentiometer<\/p><\/div>\n<h2>C#.NET Program<\/h2>\n<p>As we can see the program is really simple. The first few lines created an AnalogInput instance and set its range from 10 to 1000. Then another instance of OutPort has been created to send the signal to an LED. Then we have a very simple infinite loop which will turn the LED to on and off. The delay value is coming from the Analog Input which is a potentiometer in our case. If the analog value is 50 then the LED will turn on for 50 milliseconds and then stay off for the same amount of time.<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"csharp\" style=\"font-family:monospace;\"><span style=\"color: #008080; font-style: italic;\">\/\/ use any analog pin<\/span>\nAnalogInput aInPin <span style=\"color: #008000;\">=<\/span> <span style=\"color: #008000;\">new<\/span> AnalogInput<span style=\"color: #008000;\">&#40;<\/span>Pins<span style=\"color: #008000;\">.<\/span><span style=\"color: #0000FF;\">GPIO_PIN_A1<\/span><span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008000;\">;<\/span>\n&nbsp;\n<span style=\"color: #008080; font-style: italic;\">\/\/ give a range.<\/span>\naInPin<span style=\"color: #008000;\">.<\/span><span style=\"color: #0000FF;\">SetRange<\/span><span style=\"color: #008000;\">&#40;<\/span><span style=\"color: #FF0000;\">10<\/span>, <span style=\"color: #FF0000;\">1000<\/span><span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008000;\">;<\/span> \n&nbsp;\n<span style=\"color: #008080; font-style: italic;\">\/\/ at D1, we will send signal for LED<\/span>\nOutputPort led <span style=\"color: #008000;\">=<\/span> <span style=\"color: #008000;\">new<\/span> OutputPort<span style=\"color: #008000;\">&#40;<\/span>Pins<span style=\"color: #008000;\">.<\/span><span style=\"color: #0000FF;\">GPIO_PIN_D1<\/span>, <span style=\"color: #0600FF; font-weight: bold;\">false<\/span><span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008000;\">;<\/span>\n&nbsp;\n<span style=\"color: #0600FF; font-weight: bold;\">while<\/span> <span style=\"color: #008000;\">&#40;<\/span><span style=\"color: #0600FF; font-weight: bold;\">true<\/span><span style=\"color: #008000;\">&#41;<\/span>\n<span style=\"color: #008000;\">&#123;<\/span>\n    <span style=\"color: #008080; font-style: italic;\">\/\/ Read Pot value<\/span>\n    <span style=\"color: #6666cc; font-weight: bold;\">int<\/span> potValue <span style=\"color: #008000;\">=<\/span> <span style=\"color: #008000;\">&#40;<\/span><span style=\"color: #6666cc; font-weight: bold;\">int<\/span><span style=\"color: #008000;\">&#41;<\/span>aInPin<span style=\"color: #008000;\">.<\/span><span style=\"color: #0000FF;\">Read<\/span><span style=\"color: #008000;\">&#40;<\/span><span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008000;\">;<\/span>\n    Debug<span style=\"color: #008000;\">.<\/span><span style=\"color: #0000FF;\">Print<\/span><span style=\"color: #008000;\">&#40;<\/span><span style=\"color: #666666;\">&quot;Pot Value: &quot;<\/span> <span style=\"color: #008000;\">+<\/span> potValue<span style=\"color: #008000;\">.<\/span><span style=\"color: #0000FF;\">ToString<\/span><span style=\"color: #008000;\">&#40;<\/span><span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008000;\">;<\/span>\n&nbsp;\n    <span style=\"color: #008080; font-style: italic;\">\/\/ turn LED ON<\/span>\n    led<span style=\"color: #008000;\">.<\/span><span style=\"color: #0000FF;\">Write<\/span><span style=\"color: #008000;\">&#40;<\/span><span style=\"color: #0600FF; font-weight: bold;\">true<\/span><span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008000;\">;<\/span>\n    <span style=\"color: #008080; font-style: italic;\">\/\/ let it be ON for potValue<\/span>\n    Thread<span style=\"color: #008000;\">.<\/span><span style=\"color: #0000FF;\">Sleep<\/span><span style=\"color: #008000;\">&#40;<\/span>potValue<span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008000;\">;<\/span>\n&nbsp;\n    <span style=\"color: #008080; font-style: italic;\">\/\/ turn LED OFF and let it stay OFF for potValue<\/span>\n    led<span style=\"color: #008000;\">.<\/span><span style=\"color: #0000FF;\">Write<\/span><span style=\"color: #008000;\">&#40;<\/span><span style=\"color: #0600FF; font-weight: bold;\">false<\/span><span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008000;\">;<\/span>\n    Thread<span style=\"color: #008000;\">.<\/span><span style=\"color: #0000FF;\">Sleep<\/span><span style=\"color: #008000;\">&#40;<\/span>potValue<span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008000;\">;<\/span>\n<span style=\"color: #008000;\">&#125;<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n<h2>Outputs<\/h2>\n<p>You will see the LED will blink and its blinking rate is dependent on potentiometer (pot) value. If you turn the pot all the way to one end, it will stay ON for a second and OFF for a second. Similarly, if you turn the pot all the way to the other side, LED will appear flickering because it\u2019s only staying ON for 10th\u00a0of a second. A short Video&#8230;<\/p>\n<p><iframe loading=\"lazy\" src=\"http:\/\/www.youtube.com\/embed\/XKwtv5AmMPo\" frameborder=\"0\" width=\"560\" height=\"315\"><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<h2>Downloads<\/h2>\n<p>1)\u00a0<a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/11\/EmbeddedLab.NetduinoPlus.Day1_.zip\" target=\"_blank\">C#.NET code (A complete solution file)<\/a><\/p>\n<p>2)\u00a0<a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/11\/Lab1_FlashLEDwithPot.fzz_.zip\" target=\"_blank\">Fritzing File<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>What Next<\/h2>\n<p>In our next tutorial, we will learn about LCD (Liquit Crystal Display) and display the information that we want in the LCD. In this next tutorial, we will learn several options to send command or display the information in the LCD.\u00a0<strong>Interfacing a Character LCD with Netduino Plus<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We will start our Netduino tutorial series with a very basic project of flashing an LED. The objective of this project is to explore basics of Netduino I\/O pins as well as to make sure that everything is setup correctly, including software installation and hardware setup.\u00a0In this project, we will use an Analog pin to read a potentiometer&#8217;s analog output, and a digital pin to flash an LED. The frequency of LED blinking is varied based on the potentiometer output. It will blink at an interval of 10 milliseconds to 1000 milliseconds based on the wiper position of the potentiometer.<\/p>\n","protected":false},"author":4,"featured_media":6481,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[495],"tags":[503,502,18,1316,500,499,501],"class_list":["post-6292","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-netduino","tag-blinking-led","tag-flashing-led","tag-led","tag-netduino","tag-netduino-plus","tag-potentiometer","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/6292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=6292"}],"version-history":[{"count":93,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/6292\/revisions"}],"predecessor-version":[{"id":7473,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/6292\/revisions\/7473"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/6481"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=6292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=6292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=6292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}