Amps & Resistor for LED

Hello, i have bought a typical LED from an electronic store.

I want to connect and blink the LED from an analog pin of Arduino MEGA 2560. I have some simple questions.

  1. What is the current of an analog pin of Arduino Mega 2560? Is it the same with a digital pin?

  2. How much current does a typical LED need? And how do I know the value of the resistor i should add?

  3. The resistor is connected between the Anode and the Analog pin?

You decide how much current to put through the LED. More current = brighter. Too much current = fried LED.

Formula for the resistor: (Vpin - Vled) / Iled = R

Vled is the forward voltage drop of the LED, which you can get from the datasheet. Typical value are found online by color of LED.

Don't over-analyze it, though. Use a 1K ohm resistor. If it's too dim, use a 470 ohm. Done.

Analog pins are for analog INPUT. Why do you want to use one to OUTPUT to an LED?

Steve

Question is, why use the analogue pins on a Mega as digital out.
Did you run out of pins (for LEDs).

Yes, analogue pins have the same output specs as other digital pins.
~20mA max, and 40mA absolute max.
But if you're driving lots of LEDs, then you must also watch max port (group of 8 pins) current and max chip current.
Leo..

Thank you all for the answers.

I am just doing some tests with analog and digital pins and want to calculate the Amps. When i made a project with Arduino Uno i run out of digital pins, so i decided to connect the LEDs with analog pins and worked. For that reason, sometimes i connect LEDs with analog pins.

To sum up, are these below correct?

Is the Voltage of an analog pin 5 V?
Is the forward voltage drop of a LED about 2 V?
If i put a resistor 330Ω, how do I calculate the current?

(5V - 2V) / 330 Ω = 9 mA

Is that right?

330 Ohms is fine...

Is the Voltage of an analog pin 5 V?

Yes, the output pins are either 5V (approximately) when high and 0V (approximately) when low.

The Arduino doesn't have true-analog outputs. analogWrite() is [u]PWM[/u] which blinks the LED on & off faster than you can see so it appears to dim.

(The Arduino does have an analog-to-digital converter so it does have true analog inputs.)

Is the forward voltage drop of a LED about 2 V?

That's usually about right for a "standard" LED and it's usually a good-enough approximation if you don't have the actual specs.

If i put a resistor 330Ω, how do I calculate the current?

(5V - 2V) / 330 Ω = 9 mA

Right!

Thank you very much for the clear answer.

I have two final questions.

1. What is the max current of a digital pin, a 5V pin and a 3.3V pin?

I have read many different values and I'm a little bit confused. For instance:

  • For a digital pin: 40 mA MAX for one pin, 200 for all together.
  • For 5V pin: 400 mA (Is 400 mA for every 5V pin or for all together?)
  • For 3.3V pin: 150 mA (Is 150 mA for everry 3.3V pin or for all together?)

2. If I connect on the same 5V pin of arduino 3 components, how can i calculate it in order to make sure that they can work the same 5V pin?
The 3 components can be: LCD screen 16X2, MQ3 Sensor, GPS Module Neo 6M. Do i have to search in their datasheet about the current that every component needs, then do the sum of the 3 currents and check if the finally value is more than the 5V pin's current?

Depends on which Arduino we're talking about.
Max chip current can be 200mA (Uno) or 400mA (Mega).
Then there is port (group of 8 pins) current (100mA).
It's all in the datasheet if the chip(s) used.

A 5volt I/O pin has a max of ~20mA, and an absolute max of 40mA.
3.3volt I/O pins are usually about half of that.

The 5volt power pin is another story.
On USB supply it's 500mA minus the current the Arduino itself uses (~70mA for a Mega, ~50mA for an Uno).
Less (input voltage dependent) if you power the Arduino externally, on the DC socket or V-in.

The (single) 3.3volt power pin on the Uno/Mega comes from a tiny regulator that takes it's power from the 5volt supply.
It's rated for 150mA. But in small board Arduinos it could come from the USB<>Serial chip (<=50mA).

Yes, you do need to read the datasheets of the sensors (or ask here, with a link provided).
LCD and GPS modules are not that power-hungry, but an MQ3 has a heating element that draws 150mA.
Leo..

Mega - 800mA. 4 VCC & Gnd pins, each capable of 200mA.

Assuming the regulator does not overheat supplying that. And of cours the USB only supplies 500mA.

"But in small board Arduinos it could come from the USB<>Serial chip (<=50mA)."
Only those with an FTDI chip (Nano, if it's real Arduino).
Other variants may have 3.3V regulators which can supply more.

"Analog pins are for analog INPUT."

One function of the Analog pins is reading analog values.
They are otherwise digital IO pins, D54 to D69.