Offline
Full Member
Karma: 0
Posts: 192
|
 |
« on: January 05, 2012, 02:05:59 pm » |
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
Brattain Member
Karma: 242
Posts: 16485
Available for Design & Build services
|
 |
« Reply #1 on: January 05, 2012, 02:23:41 pm » |
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
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 192
|
 |
« Reply #2 on: January 05, 2012, 03:40:36 pm » |
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
Edison Member
Karma: 43
Posts: 2491
"We're a proud service of the Lost Electricity Reclamation Agency"
|
 |
« Reply #3 on: January 05, 2012, 05:01:09 pm » |
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
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 242
Posts: 16485
Available for Design & Build services
|
 |
« Reply #4 on: January 06, 2012, 01:05:52 am » |
Yes, nice catch Jack. Not enough thought behind my quick answer.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 192
|
 |
« Reply #5 on: January 06, 2012, 06:55:05 am » |
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
God Member
Karma: 0
Posts: 591
|
 |
« Reply #6 on: January 06, 2012, 07:49:17 am » |
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
Faraday Member
Karma: 131
Posts: 4655
|
 |
« Reply #7 on: January 06, 2012, 08:17:48 am » |
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
Full Member
Karma: 0
Posts: 192
|
 |
« Reply #8 on: January 06, 2012, 08:39:34 am » |
i don't really understand, could anyone give me an illustration on how to wire that up?
|
|
|
|
|
Logged
|
|
|
|
|
United Kingdom
Offline
Faraday Member
Karma: 131
Posts: 4655
|
 |
« Reply #9 on: January 06, 2012, 09:38:37 am » |
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
God Member
Karma: 3
Posts: 812
|
 |
« Reply #10 on: January 06, 2012, 02:15:05 pm » |
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
Brattain Member
Karma: 242
Posts: 16485
Available for Design & Build services
|
 |
« Reply #11 on: January 06, 2012, 02:55:11 pm » |
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/BobuinoRev17I 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
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 192
|
 |
« Reply #12 on: January 06, 2012, 04:31:28 pm » |
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
Brattain Member
Karma: 242
Posts: 16485
Available for Design & Build services
|
 |
« Reply #13 on: January 06, 2012, 04:38:11 pm » |
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
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 192
|
 |
« Reply #14 on: January 06, 2012, 04:49:32 pm » |
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
|
|
|
|
|
|