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.

REQUIREMENTS,

  1. 1ok potentiometer
  2. 220 ohms resistor
  3. LED
  4. Arduino board
  5. Jumper wires 
  6. Breadboard

WIRING DIAGRAM 

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.  

 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,    

SOFTWARE 

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 https://xod.io/downloads/   

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. 

 Or you can simply go to the project browser then look for led and POT as potentiometer. 

 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. 

 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. 

 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. 

 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;

int potPin= A5;  //Declare potPin to be analog pin A0

int LEDPin= 7;  // Declare LEDPin to be arduino pin 7 or 9

int readValue;  // Use this variable to read Potentiometer

int writeValue; // Use this variable for writing to LED

void setup() {

 pinMode(potPin, INPUT);  //set potPin to be an input

 pinMode(LEDPin, OUTPUT); //set LEDPin to be an OUTPUT

 Serial.begin(9600);      // turn on Serial Port

}

void loop() {  

readValue = analogRead(potPin);  //Read the voltage on the Potentiometer

writeValue = (255./1023.) * readValue; //Calculate Write Value for LED

analogWrite(LEDPin, writeValue);      //Write to the LED

Serial.print("You are writing a value of ");  //for debugging print your values Serial.println(writeValue);

}

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 -- https://xod.io/
XOD Community -- 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 here. then thank you, guys!
 

Sort:  

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

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!

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.032
BTC 64117.78
ETH 3112.19
USDT 1.00
SBD 4.23