How to adjust LED brightness using potentiometer/ visual programming XOD

in #utopian-io7 years ago (edited)

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.

20180114_142700.jpg

In order 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 thid tutorial.

REQUIREMENTS,

  • 1ok potentiometer
  • 220 ohms resistor
  • LED
  • Arduino board
  • Jumper wires 
  • Breadboard

  • CIRCUIT DIAGRAM

    lumin.png

    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 allow current to pass when you push it down and block electricity when you let it go.

    20180114_124010.jpg

    I started to put the 220 ohm resistor, and 3 red leds, coonect 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 connectb it to the same rail on the breadboard,
    20180114_124225.jpg

    SOFTWARE
    we will going to use 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 dorectly to the 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/

    xoxox.png

    I have downloaded it already on my pc, so lets start working on the code, onc eyou 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.

    111.png

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

    222.png

    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.

    3333.png

    click on the LED node, then again edit the port where the led pin is connected, as myexample i put the led pin to digital pin 7 on the arduino so i put 7 on the port.

    4444.png

    Now lets 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 potentiomenter to control the luminance so we dont need to put a lum on led. once done, click on the DEPLOY tan then upload to arduino.

    5555.png

    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 thats bcoz i only using 1 1ok potentiometer and i tried to put 3 leds but the potentionmeter woks 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. s lets take a look and try to control the leds using the potentiometer.

    If yu are going to use the arduino ide you can copy the skecth 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); 
    }

    20180114_142157[1].gif

    So thats it, i hope this small project got you an idea:) if you have qustion 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. then thank you guys!


    You can also check my previous posts:
    How to make 12 LED chaser without shift
    Control LED using Push Buttons/ Visual programming using XOD
    Control Servo motor using Joystick
    Stepper motor + Driver Uln2003 in arduino
    Control Servo motor using potentiometer - arduino



    Posted on Utopian.io - Rewarding Open Source Contributors

    Sort:  

    Thanks for sharing this post.I already has been
    this post about LED potebtiomitre.

    Thank you for the contribution. It has been approved.

    • Please follow the format prescribed next time. Including the “what I will learn”, “requirements”, “difficultly level”.
      You can contact us on Discord.
      [utopian-moderator]

    noted thank you

    Hello, you received a boost courtesy of @steemdunk! Steem Dunk is an automated curation platform that is easy and free for use by everyone. Need a boost? Click me

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

    Hey @pakganern I am @utopian-io. I have just upvoted you!

    Achievements

    • Seems like you contribute quite often. AMAZING!

    Suggestions

    • Contribute more often to get higher and higher rewards. I wish to see you often!
    • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

    Get Noticed!

    • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

    Community-Driven Witness!

    I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

    mooncryption-utopian-witness-gif

    Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

    Coin Marketplace

    STEEM 0.26
    TRX 0.25
    JST 0.039
    BTC 94802.39
    ETH 3313.10
    USDT 1.00
    SBD 3.32