Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1
    10+ Posting Member
    Join Date
    Oct 2012
    Location
    Israel
    Posts
    10
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    LED turning ON on LOW, OFF on HIGH

    Hi guys!

    I'm kinda new here, just started building my own home cockpit lately, and just got into Arduino

    I'm trying to make my LED indicators, and I've come up with a strange problem,
    Whenever I use
    digitalWrite(7, LOW);

    The LED turns ON!

    And the opposite applies as well!

    i.e:

    if (noseGear != noseGearOld){
    if(noseGear == "000"){
    digitalWrite(7, LOW);
    }

    Turns the LED ON

    What am I doing wrong?

    Thanks!
    Michael

  2. #2
    25+ Posting Member zulucat's Avatar
    Join Date
    Sep 2012
    Location
    Southern SoCal
    Posts
    36
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: LED turning ON on LOW, OFF on HIGH

    Quote Originally Posted by Mavni View Post
    What am I doing wrong?
    Nothing!

    A brief tutorial. A LED needs power, ground and a current limiting resistor to work. LEDS are polarized; that is, there is a plus (+) side and a minus (-) side. The (+) side goes to power and the (-) side goes to ground. I'm going to use "->" to indicate a connection between components. Arduino systems use +5 volts so ----

    +5v -> (+)led(-) -> resistor -> gnd

    or

    +5v -> resistor -> (+)led(-) -> gnd

    These two methods of hooking up a led are electrically equivalent. Either one of these will work correctly.

    For the led to operate as you describe the output pin of the Arduino must be connected to ground (gnd) side of the circuit. When you set the pin LOW you are completing the circuit.

    If you connect the output pin to the +5v side of the circuit the led will light when the pin goes HIGH. Don't forget to disconnect +5v and connect ground.

    Doug -

  3. #3
    10+ Posting Member
    Join Date
    Oct 2012
    Location
    Israel
    Posts
    10
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: LED turning ON on LOW, OFF on HIGH

    Thanks, Doug!

    I needed that little lesson...

    This is my current setup, if you can see in the photo
    Attachment 7328
    I have a 10K resistor connected from 5v to the LED, but I haven't connected the grd,
    Just the output pin from Arduino...
    noobish, I know...

    when I connected it to grd it stayed on all the time, but I suspect it was a code problem

    One more small thing, I know 10K resistors are way OP for a LED, but the other ones I got is either 330Ohms and 100Ohms,
    What is the minimum resistor value I can use?
    Is it bad to use OP'ed resistors?

    Thanks again
    Michael

  4. #4
    25+ Posting Member zulucat's Avatar
    Join Date
    Sep 2012
    Location
    Southern SoCal
    Posts
    36
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: LED turning ON on LOW, OFF on HIGH

    This is my current setup, if you can see in the photo
    The link to the attachment doesn't work. I've notified the site admin.

    I have a 10K resistor connected from 5v to the LED, but I haven't connected the grd. Just the output pin from Arduino...noobish, I know...
    This is a correct way of hooking up the led.

    when I connected it to grd it stayed on all the time, but I suspect it was a code problem
    It's not a code problem. That's what should happen. You were supplying a permanent ground for the circuit. I guess I wasn't clear enough in my previous post. The output of the Arduino is used IN PLACE OF the ground connection. Here's how it should look currently:

    +5v -> resistor -> (+)led(-) -> UNO

    If you want to have the led light when the output is high do this:

    UNO -> resistor -> (+)led(-) -> gnd


    IOne more small thing, I know 10K resistors are way OP for a LED, but the other ones I got is either 330Ohms and 100Ohms, What is the minimum resistor value I can use? Is it bad to use OP'ed resistors?
    Most leds I'm familiar with have a current limit of 20mA. You can use this formula to calculate resistance.

    R = E/I

    Where R is resistance in ohms, E = voltage and I = current in amps. So, R = 5/0.020 = 250 ohms. This would give you maximun brightness. Because of manufacturing tolerances I would go up to 270 or even 330. As you increase resistance you decrease the current flow through the led which, in turn, decreases brightness.

    If you have a datasheet on the led you may want to verify that 20mA is the upper limit for the one you are using.

    I don't know what the terms "OP" and "OP'ed" mean. Could you please explain?

    Doug -

  5. #5
    10+ Posting Member
    Join Date
    Oct 2012
    Location
    Israel
    Posts
    10
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: LED turning ON on LOW, OFF on HIGH

    OP means overpowered...

    I changed the setup so now it's: mega->resistor->LED->grd
    Seems to be working just fine, i also changed the resistors to 100Ohms, because this gives me maximum brightness
    What does that say about my LEDs, that they are not 20MmA? (just so I fully understand the logic)
    I don't have anything on this LED, it's just a cheap LED bought from a local store

    Michael

  6. #6
    25+ Posting Member zulucat's Avatar
    Join Date
    Sep 2012
    Location
    Southern SoCal
    Posts
    36
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: LED turning ON on LOW, OFF on HIGH

    Quote Originally Posted by Mavni View Post
    ... i also changed the resistors to 100 Ohms ...
    Stop doing that RIGHT NOW. A 100 ohm resistor limits current flow to 50mA. That's 10mA above what the Mega is specified as providing. I don't know at what point the Mega will fail but I wouldn't push it! Use the 330 ohm resistor and live with it.

  7. #7
    10+ Posting Member
    Join Date
    Oct 2012
    Location
    Israel
    Posts
    10
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: LED turning ON on LOW, OFF on HIGH

    Thanks for that heads' up!
    I'm replacing them now...

    So how can I make them brighter?
    Do I need better quality LEDs?

    Thanks again...

  8. #8
    10+ Posting Member
    Join Date
    Oct 2012
    Location
    Israel
    Posts
    10
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: LED turning ON on LOW, OFF on HIGH

    So what you're saying is that I should NEVER use 100Ohms for the Arduino?

  9. #9
    150+ Forum Groupie


    jonesthesoftware's Avatar
    Join Date
    Jul 2009
    Location
    aberdare, south wales UK
    Posts
    276
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: LED turning ON on LOW, OFF on HIGH

    Hi guys
    a quick clarification here, to calculate the resistor to put in series with an led use the formula
    R=Vs-Vf/If
    where Vs is your supply volts(5 volts in your case). Vf Is the forward voltage drop of the led from its data sheet(generally in the region of 2.5 - 3.2 volts) and If is the desired current through the led(generally about 20 mA) . The Arduino digital outputs can source 40 mA each so no problem there.
    5-3.2= 1.8volts so 1.8/0.02=90 ohms so 100 ohm resistor is OK.
    Regards
    geoff

  10. #10
    10+ Posting Member
    Join Date
    Oct 2012
    Location
    Israel
    Posts
    10
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: LED turning ON on LOW, OFF on HIGH

    OK, Now I'm really confused...
    Do I need to use a stronger resistor for the first LED in a series?
    Or do I choose a resistor based on how many LEDs I have in general?

    I have 6 LEDs on this specific setup (Gear Indicator), but I do want around 20 more indicators, most of them will be 1/2 LEDs each

    Michael

Page 1 of 2 12 LastLast

Tags for this Thread