How to control The Luminance of LED using XOD Visual programming

in #dblog5 years ago

In this instructable, I am going to share how to control the led adjustable brightness. The brightness will be set based on the position of the potentiometer. To do this, we need to set the potentiometer up as a voltage divider, and we need to drive the LED from one of the pins. For this example, I am using pin 9. The circuit schematic I am using is shown below. but we will write first the requirements for this tutorial.

<p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fW152J8GqWhyqzcj2BFFuw4uzL3DCsjrZHuH895TdQ?format=match&mode=fit&width=640" srcset="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fW152J8GqWhyqzcj2BFFuw4uzL3DCsjrZHuH895TdQ?format=match&mode=fit&width=640 1x, https://images.hive.blog/1536x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fW152J8GqWhyqzcj2BFFuw4uzL3DCsjrZHuH895TdQ?format=match&mode=fit&width=640 2x" /> <p dir="auto">REQUIREMENTS, <ol> <li>1ok potentiometer <li>220 ohms resistor <li>LED <li>Arduino board <li>Jumper wires  <li>Breadboard <p dir="auto"><strong>WIRING DIAGRAM  <p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fVzqnYHQGZFcNg8zQ3QCuXg7fuo2xGrP97Dwhg7Hrn?format=match&mode=fit&width=640" srcset="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fVzqnYHQGZFcNg8zQ3QCuXg7fuo2xGrP97Dwhg7Hrn?format=match&mode=fit&width=640 1x, https://images.hive.blog/1536x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fVzqnYHQGZFcNg8zQ3QCuXg7fuo2xGrP97Dwhg7Hrn?format=match&mode=fit&width=640 2x" /> <p dir="auto">In placing the LED into the breadboard, remember that you must always put the longer leg towards the positive voltage(anode). In the case above, the longer leg should be connected to the resistor, and the shorter leg connected to ground(cathode). Also, remember that we are using a 220-ohm resistor in the circuit to limit the current flow through the LED, it allows electricity to pass when you push it down and block electricity when you let it go.   <p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fW1517jp8MonS4Q7SYDeTbnn3oHmDLvZ5RVtiaEhwL?format=match&mode=fit&width=640" srcset="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fW1517jp8MonS4Q7SYDeTbnn3oHmDLvZ5RVtiaEhwL?format=match&mode=fit&width=640 1x, https://images.hive.blog/1536x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fW1517jp8MonS4Q7SYDeTbnn3oHmDLvZ5RVtiaEhwL?format=match&mode=fit&width=640 2x" /> <p dir="auto"> I started to put the 220-ohm resistor, and 3 red LEDs, connect the short leg or the common cathode leg of the led on the horizontal rail on the breadboard, put resistor on the long leg of the led then connect it to the same rail on the breadboard,     <p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfJnH4ssCf3iDTdaL9eaJ9nVcV6yzwKWmCbZHZLS?format=match&mode=fit&width=640" srcset="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfJnH4ssCf3iDTdaL9eaJ9nVcV6yzwKWmCbZHZLS?format=match&mode=fit&width=640 1x, https://images.hive.blog/1536x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfJnH4ssCf3iDTdaL9eaJ9nVcV6yzwKWmCbZHZLS?format=match&mode=fit&width=640 2x" /> <p dir="auto"><strong>SOFTWARE  <p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfLaM5Y66g3tm4ijNVMGqy12SYqisJchPaQQffvE?format=match&mode=fit&width=640" srcset="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfLaM5Y66g3tm4ijNVMGqy12SYqisJchPaQQffvE?format=match&mode=fit&width=640 1x, https://images.hive.blog/1536x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfLaM5Y66g3tm4ijNVMGqy12SYqisJchPaQQffvE?format=match&mode=fit&width=640 2x" /> <p dir="auto">we will be using visual programming using XOD application, here is a brief info about the software, on installing XOD you use the XOD integrated development environment (IDE for short), which comes in two flavors: browser-based and desktop version but to upload the the sketch directly to the Arduino uno its better to download the software. It works on Windows, macOS, and Linux. Find a distribution package for your system on <a href="https://xod.io/downloads/" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://xod.io/downloads/    <p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfMm1JtsiKCkPnjzKPo7JG8UaqJ9DoqCfYhBBwuQ?format=match&mode=fit&width=640" srcset="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfMm1JtsiKCkPnjzKPo7JG8UaqJ9DoqCfYhBBwuQ?format=match&mode=fit&width=640 1x, https://images.hive.blog/1536x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfMm1JtsiKCkPnjzKPo7JG8UaqJ9DoqCfYhBBwuQ?format=match&mode=fit&width=640 2x" /> <p dir="auto">I have downloaded it already on my pc, so lets start working on the code, once you have open the software there a lot of guide there on how its work, so I m going start a new project on how to adjust the lumination of the led using the potentiometer, lets start to set up the led node form the ide. just double click on the nodes table the search bar will appear and search for the word LED.  <p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfMm1JtsiKCkPnjzKPo7JG8UaqJ9DoqCfYhBBwuQ?format=match&mode=fit&width=640" srcset="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfMm1JtsiKCkPnjzKPo7JG8UaqJ9DoqCfYhBBwuQ?format=match&mode=fit&width=640 1x, https://images.hive.blog/1536x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfMm1JtsiKCkPnjzKPo7JG8UaqJ9DoqCfYhBBwuQ?format=match&mode=fit&width=640 2x" /> <p dir="auto"> Or you can simply go to the project browser then look for led and POT as potentiometer.  <p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfNMc2TQcb4FzU1ucM4Jh8W8VQU5wmEdUmcLDDQJ?format=match&mode=fit&width=640" srcset="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfNMc2TQcb4FzU1ucM4Jh8W8VQU5wmEdUmcLDDQJ?format=match&mode=fit&width=640 1x, https://images.hive.blog/1536x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfNMc2TQcb4FzU1ucM4Jh8W8VQU5wmEdUmcLDDQJ?format=match&mode=fit&width=640 2x" /> <p dir="auto"> once done, click on the potentiometer node POT then edit the port where the pin is connected. as my example, I put the potentiometer to the analog pin A5 so I put 5 on the port.  <p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfPZUqY3kq1mAFPFs1cUXG2eCXPHkcTXdbvVazSr?format=match&mode=fit&width=640" srcset="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfPZUqY3kq1mAFPFs1cUXG2eCXPHkcTXdbvVazSr?format=match&mode=fit&width=640 1x, https://images.hive.blog/1536x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbfPZUqY3kq1mAFPFs1cUXG2eCXPHkcTXdbvVazSr?format=match&mode=fit&width=640 2x" /> <p dir="auto"> Click on the LED node, then again edit the port where the led pin is connected, as my example I put the led pin to digital pin 7 on the Arduino so I put 7 on the port.  <p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbhwV77W7db8R9cq9HJrZCDfFXLE8Wx9ZEVheXxrJ?format=match&mode=fit&width=640" srcset="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbhwV77W7db8R9cq9HJrZCDfFXLE8Wx9ZEVheXxrJ?format=match&mode=fit&width=640 1x, https://images.hive.blog/1536x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbhwV77W7db8R9cq9HJrZCDfFXLE8Wx9ZEVheXxrJ?format=match&mode=fit&width=640 2x" /> <p dir="auto"> Now let us connect the potentiometer VAL to LUM of the led, the lum or luminance is the brightness of the led, you can put 0-1 on the lum 0 means off, but we are going to use a potentiometer to control the luminance so we don't need to put a LUM on led. once done, click on the DEPLOY tan then upload to Arduino.  <p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbhxgaKGnwkEpTvqYxfBnnNBNkjmUoedhzTeLV5cz?format=match&mode=fit&width=640" srcset="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbhxgaKGnwkEpTvqYxfBnnNBNkjmUoedhzTeLV5cz?format=match&mode=fit&width=640 1x, https://images.hive.blog/1536x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbhxgaKGnwkEpTvqYxfBnnNBNkjmUoedhzTeLV5cz?format=match&mode=fit&width=640 2x" /> <p dir="auto"> As you can see on the circuit diagram I use 3 LEDs but on the visual sketch on xod I use only 1 led node that's bcoz I only using 1 1ok potentiometer and I tried to put 3 LEDs but the potentiometer works only in 1 led and the 2 led is just turning on and off. the 3 LEDs is connected to 1 parallel circuit which means its all connected into one led. let's take a look and try to control the LEDs using the potentiometer. If you are going to use the Arduino ide you can copy the sketch code below; <p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbkdoRPPuMMgG7ao61uXWHjM6gFxuZBLCcp7jpWBP?format=match&mode=fit" srcset="https://images.hive.blog/768x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbkdoRPPuMMgG7ao61uXWHjM6gFxuZBLCcp7jpWBP?format=match&mode=fit 1x, https://images.hive.blog/1536x0/https://steemitimages.com/p/3W72119s5BjWMGm4Xa2MvD5AT2bJsSA8F9WeC71v1s1fKfGkK9mMKuc3LcvF4KigbWg9UsrpEPG4fWbkdoRPPuMMgG7ao61uXWHjM6gFxuZBLCcp7jpWBP?format=match&mode=fit 2x" /> <pre><code>int potPin= A5;  //Declare potPin to be analog pin A0<br /> <br /> int LEDPin= 7;  // Declare LEDPin to be arduino pin 7 or 9 <br /> <br /> int readValue;  // Use this variable to read Potentiometer<br /> <br /> int writeValue; // Use this variable for writing to LED<br /> <br /> void setup() {<br /> <br />  pinMode(potPin, INPUT);  //set potPin to be an input<br /> <br />  pinMode(LEDPin, OUTPUT); //set LEDPin to be an OUTPUT<br /> <br />  Serial.begin(9600);      // turn on Serial Port<br /> <br /> }<br /> <br /> void loop() {  <br /> <br /> readValue = analogRead(potPin);  //Read the voltage on the Potentiometer<br /> <br /> writeValue = (255./1023.) * readValue; //Calculate Write Value for LED<br /> <br /> analogWrite(LEDPin, writeValue);      //Write to the LED<br /> <br /> Serial.print("You are writing a value of ");  //for debugging print your values Serial.println(writeValue); <br /> <br /> } <p dir="auto">So that's it, I hope this small project got you an idea:) if you have questions about the XOD you can check this out: XOD Official -- <a href="https://xod.io/" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://xod.io/<br /> XOD Community -- <a href="https://forum.xod.io/" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://forum.xod.io/, and thank you for to toptechboy for this wonderful stuff. I alreaddy post this Tutorial on utopian if you want to see it click <a href="https://steemit.com/utopian-io/@pakganern/how-to-adjust-led-brightness-using-potentiometer-visual-programming-xod" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">here. then thank you, guys!<br />  
Sort:  


dblog logo w white background.jpgThis post is manually curated by @dblog.supporter.

Hello, as a member of @steemdunk you have received a free courtesy boost! Steemdunk is an automated curation platform that is easy to use and built for the community. Join us at https://steemdunk.xyz

Upvote this comment to support the bot and increase your future rewards!