I am new to Arduino, and I am running out of pins.
So I decided rather using RGB LEDs for my project I will show two different level of brightness with same LED. Thus it will eventually helpful me to show that player 1 is having brighter red LED and player 2 is having lesser bright LED.
But the problem is,
I connect +ve pin of a LED to digital output pin 3 through 330 ohm resistor to show brighter LED (for player 1) and -ve pin to Arduino ground
I also connect the same +ve pin to analog pin A0 as output through 10k resistor to show lesser bright LED (for player 2) and negative pin to Arduino ground
So when, I set pin 3 high, it will show brighter LED.
But at the same time, the analog output pin A0 is set to low. So, the current will also flow through the 10k resistor to the analog pin which is at ground or 0 volt and it is an output pin.
Will this damage the board or my LED in any way? As I am sending voltage and current to the output pin and not an input pin.
I understand that input pin will not have any effect but it is output pin, and it should not be having an voltage input.
If I use 4th digital pin as output instead of Analog pin A0, will it also have effect on my board or the LED?
Will it be harmful to my board or any other electronic components attached to Arduino board?
This should not cause any problems , but a better method would be to use a PWM pin - you can then easily set the brightness under software control . Just connect the led to one of these pins through your 330ohm resistor .
sundram_kumar:
the analog output pin A0 is set to low.
That's NOT an analog output. It's a pin you can use as analog input. But right here, you're just using it as a digital output.
Isn't it easier to just connect two LED's if you're already using two pins?
But it should not cause a short circuit because of the resistor. But the LED will not light if you make A0 HIGH and 3 LOW. You just made a voltage divider with a 10k and a 330Ohm which just gives 160mV which is very much below the VF of the LED. You can solve this by NOT setting A0 or 3 LOW when you want to turn it off but by letting it float aka make it an input. So instead of digitalWrite(pin, LOW), do pinMode(pin, INPUT).
But again, why not use two leds? And note, there are many other solutions if you want to save pins. For example, software PWM or using the float state for a second brightness.
Last is easiest. With the before mentioned 10k and 330Ω, do it like:
Vcc
|
10k
|
pin---|
|
330Ω
|
LED
|
GND
If you set the pin:
LOW (pinMode(pin, OUTPUT); digitalWrite(pin, LOW)) => LED off
HIGH (pinMode(pin, OUTPUT); digitalWrite(pin, HIGH)) => LED bright
float (pinMode(pin, INPUT)) = LED dim
You may change the values but the top resistor needs to be the highest and >500Ω.
sundram_kumar:
I need total of 15 pins for my project. And I have only 6 PWM pins.
That is not too clear. Do you need 15 pins counting two pins per LED, that would seem reasonable but not the odd number of pins required. Or do you mean you want to control the brightness of 16 LEDs?