2 LED's 1 digital pin

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?

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.

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?

lyron: 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

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

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?

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

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.

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

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]

lyron: 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.

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.

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.

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.

CrossRoads: 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.

Ok, I'll track down Greg's forum name, I just got a board from him in the mail, it's pretty heft with all the screw terminals. Says it drives the segments with 9 LEDs on a strip nice & bright from 12V!

Greg is goodman1887 Here's the first board he assembled, and a clip of a test sketch of the LED strips lighting up.

http://www.crossroadsfencing.com/BobuinoRev17/led_strip_test.MOV

lyron: 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.

Sounds perfect for a i2c i/o expander. That only needs a4 and a5 and you can easily control 16 i/o pins. Have a look at a MPC23016 for 16 i/o pins or MPC23008 for 8 i/o pins.

Each i/o pin can be either input or output.

If you really want to have some fun and speed is not a critical issue, you could actually do it all with one pin using a shift register. Have a look at this article for how. It uses a pair of RC networks to drive a 74HC595 shift register. Pretty cool actually: http://www.romanblack.com/shift1.htm

--- bill

dc42:
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]

Here is the schematic, shrunken so that the forum accepts it.

Scan 66.JPG

This image was referenced earlier as a link. Reposting for reference.