1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

controlling two leds w 1 pin

Discussion in 'Microcontrollers' started by MrDEB, Aug 30, 2017.

  1. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    I want to see if it is doable to control two leds with one pic output.
    charplexing was first idea but ??
    End result is alternately blink the two leds back and forth.
    Not real important but for this application it would be better than one led blinking.
    my first thought
    5v+-----I>-----resistor---pic pin1
    grd-----<I-----resistor---pic pin1
    then just have the pic pin high / low
    not real happy with it but?? pretty basic design.
     
  2. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,795
    Likes:
    134
    Location:
    morristown,tn
    ONLINE
    If you want them both on at the same time just toggle them faster then you can see the blink.
     
  3. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    no have them blink alternately.
    Need to end this thread as I finalized my board design and sent the files to Elecrow PCB manfacturing in China
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. alec_t

    alec_t Well-Known Member Most Helpful Member

    Joined:
    Jul 10, 2011
    Messages:
    9,251
    Likes:
    1,218
    Location:
    Cardiff, Wales

    Do you mean 1-1-1-1-2-2-2-2-1-1-1-1-2-2-2-2 ..... or 1-2-1-2-1-2-1-2 ..... ?
     
  6. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,795
    Likes:
    134
    Location:
    morristown,tn
    ONLINE
    It's simple you set port high led A is on then led B is off you set port Low B is on A is off set port to tr-state both leds are off.

    Want both toggle them faster then you can see them blink.
     
  7. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    that is exactly what I am doing, two leds, two resistors and alternate the port HIGH then LOW
    was hoping to go with something a little bit more exotic like only one resistor but went the KISS method.
     
  8. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,118
    Likes:
    90
    Location:
    Seattle, WA
    ONLINE

    As Burt says, but allow me to put it into termsMrDEB can understand.

    HIGH or LOW obviously turns one of the LEDs.

    Making the output "tristate" turns both off. For MrDEB, that means setting the port pin to INPUT.
     
  9. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,795
    Likes:
    134
    Location:
    morristown,tn
    ONLINE
    he could use one resistor but if the leds don't match one will burn out id just use 2
     
  10. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    I have two in the board design
     
  11. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,011
    Likes:
    317
    Location:
    Brisbane Australia
    If your supply is 5V then both LEDs will be lit dimmly all the time.

    Mike.
     
  12. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,118
    Likes:
    90
    Location:
    Seattle, WA
    ONLINE
    If the port pin is set as an input,

    R = 330 + 330 = 660 ohms

    Vf = 2.2 + 2.2 = 4.4 volts

    Iled = (5 - 4.4)/600 = 0.6/600 × 1000mA/1A = 1mA

    Mike is right.


    SmartSelectImage_2017-08-30-18-42-26.png
     
  13. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,795
    Likes:
    134
    Location:
    morristown,tn
    ONLINE
    I just tried this with a pic18f1220 it don't work one led blinks only did you test this.
    This is funny but I tried this with 2 pic16f1825 and 18f1220 they both wouldn't source power
    they sink and bink led. OK I figured it out bad resistor out the bag.
    It doesn't turn off the leds when set to input. I'm using two 1 k the blink not bad

     
    Last edited: Aug 30, 2017
  14. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,011
    Likes:
    317
    Location:
    Brisbane Australia
    You could have, LED - Diode - Diode - LED and a resistor from the diode junction to pic pin.

    Or, use lower voltage supply.

    Mike.
     
  15. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,795
    Likes:
    134
    Location:
    morristown,tn
    ONLINE
    I'm lazy i just lowered the voltage
     
  16. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    good point Mike.
    I would think the port pin goes LOW then only one LED will light.
    Will have to re think as per Burts example or ??
     
  17. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,795
    Likes:
    134
    Location:
    morristown,tn
    ONLINE
    Like Mike said you can turn one off one on but not both off they light up dim But with the 2 diodes 4 supply they both go off without the diodes the voltage needs to be around 3.2 volts to turn off both. it the way the port pins are made the protection diodes
     

Share This Page