Loading...
Pages: [1] 2   Go Down
Author Topic: 2 LED's 1 digital pin  (Read 849 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 192
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I would like to hook up 2 LED's to a digital pin so when i toggle it LOW one LED goes on and when i toggle it high the other goes on.

I thought i'd do it like this (i forgot to add a resistor to the digital pin):


but then the LED's would constantly be on..

and if i would add a resistor, would i need to do it like this:

                                                           ______________LED----VCC
                                                           |
                                                           |
digital_pin---------------------|330 Ohm|----|------------------LED----GND

or else?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 242
Posts: 16485
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, to resistor use.
Yes to LED use - one Anode to VCC/cathode to resistor, LOW = on; anode to resistor/cathode to GND, HIGH = on.
One or the other will always be on if pinMode is set to output.
If pinMode is set to input, very little current will flow to/from the floating pin and they should appear to be off.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Offline Offline
Full Member
***
Karma: 0
Posts: 192
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But before the pin is set to an output the two leds will be in series connected to 5v from my 1A voltage regulator. Doesn't that burn out the LEDs?
Logged

Grand Blanc, MI, USA
Offline Offline
Edison Member
*
Karma: 43
Posts: 2491
"We're a proud service of the Lost Electricity Reclamation Agency"
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

But before the pin is set to an output the two leds will be in series connected to 5v from my 1A voltage regulator. Doesn't that burn out the LEDs?

Yes, it very well could. I'd use two resistors. Having trouble uploading an image here, so please see:
http://tinypic.com/view.php?pic=r91jyd&s=5
Logged

Get the infamous "One Million Ohms" board at tINDIE.com: http://tinyurl.com/BuyMohms

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 242
Posts: 16485
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, nice catch Jack. Not enough thought behind my quick answer.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Offline Offline
Full Member
***
Karma: 0
Posts: 192
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you both,

Now: i need to do this to 14 digital pins, would i be able to do it like this:

so i only need two resistors?
Logged

Ft. Worth, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 591
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not necessarily. In that case, You will always have 14 LED's on, whether it is ground side or VCC side. Assuming a 1.9V 10mA LED, you'd have the LED's in effective parrallel, currents add, so (5 volts - 1.9 volts) / 140mA = 3.1 volts / 140mA = 22.142 ohms
Logged

KF5RVR

United Kingdom
Offline Offline
Faraday Member
**
Karma: 131
Posts: 4655
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd connect them like this:

Vcc -- Led1 A
Led1 K -- R1
R1 other end -- pin -- R2
R2 other end -- Led2 A
Led2 K -- ground

If the forward voltages of Led1 and Led2 are 3v or more each, then they shouldn't light up when the pin mode is set to INPUT. Otherwise, put a 1n4148 or similar diode in series with each led to increase its forward voltage by 0.6v.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com

Offline Offline
Full Member
***
Karma: 0
Posts: 192
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i don't really understand, could anyone give me an illustration on how to wire that up?
Logged

United Kingdom
Offline Offline
Faraday Member
**
Karma: 131
Posts: 4655
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want to connect 28 LEDs to an Arduino, you'd be much better off multiplexing them. The attached diagram shows 2 x 3 multiplexing, which you could expand to 4 x 7. C1 - C2 and R1 - R3 are Arduino pins (you'll need 11 pins for 28 LEDs). Choose the value of resistor R to get the peak current you want in each LED (20 to 25mA is probably about right).

The diagram on the right shows how I was suggesting to connect 2 LEDs to one pin. However, if they are red LEDs, then a single 1n4148 in series may not be enough.

[sorry, can't post the pics because of "uploader full" messages]
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com

Offline Offline
God Member
*****
Karma: 3
Posts: 812
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now: i need to do this to 14 digital pins, would i be able to do it like this:

No, this won't work, unless you only ever have one LED on. As you turn on more LEDs, they will want more current (in parallel), but the resistor is the same for all of them, so they have to "split" the current. You need one resistor per LED.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 242
Posts: 16485
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I just designed an ATMege328 based board for another member, Greg, uses 4 TPiC6B595 shift registers to drive 28 LED strings, you can see it at the bottom of this page.
www.crossroadsfencing.com/BobuinoRev17
I can post his member name when I get home, I am sure he'd be willing to part with a board or two, he's asked if I thought there was interest. He has some (20?) on hand now and is learning how to program them to drive 7 or 8 segment displays (using undercounter LED strings as the segments, powered by 12V).
Uses simple SPI commands to write to the registers.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Offline Offline
Full Member
***
Karma: 0
Posts: 192
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice, for my application i have a atmega328 with only A3-5 left and i need it to communicate with something else that can toggle 14 outputs(28 leds) -- 1 output can toggle 2 leds since they are 14 R/G leds.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 242
Posts: 16485
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You are using the SPI pins?  Can you move whats on them to  A3-4-5 and free up SS, SCK, MOSI so you can drive shift registers with them?
Might be able to move some of your other outputs to shift register outputs also.

To send out 4 bytes:
digitalWrite (SS, LOW);
SPI.transfer (byte1);
SPI.transfer (byte2);
SPI.transfer (byte3);
SPI.transfer (byte4);
digitalWrite (SS, HIGH); // outputs get updated on this rising edge.


Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Offline Offline
Full Member
***
Karma: 0
Posts: 192
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are using the SPI pins?  Can you move whats on them to  A3-4-5 and free up SS, SCK, MOSI so you can drive shift registers with them?

nope, sorry. I already got the board and soldered it...

Also, i think shift registers are pretty scary, i tried using them once but I think it's too much of a hassle. I think i'm just going to use softwareserial to let the board communicate with another atmega328 that drives two leds as described before (the one in my post with two resistors). I just tested the LED setup and it works just fine.

I might still be interested in the board you designed for driving 28 led strips.

Thank you for your help.
Logged

Pages: [1] 2   Go Up
Print
 
Jump to: