Questions on projects 02

Hey!

I have some questions about project 2 from Arduino Projects Book.

** Why are the LEDs connected to ground by 220-ohm resistors? how are the resistors working in this case? what if I connect the LEDs to ground with jumper wires?
Same thing for the pushbutton; why is it connected to ground by a resistor as well?

** Also, please correct me if I am wrong:
the pushbutton is connected to 5V and pin 2 as a circle just for digitalRead to know whether the pushbutton is HIGH or LOW. 5V comes to one end of the pushbutton: if the button isn't pressed, then pin 2 doesn't receive voltage- so it is LOW, and vice-versa.
Plus, the LEDs get power from the pins (computer) NOT 5V, right?

Thanks :smiley:

Hi,

  1. I don't know the arduino project book, but, basically, the 220 Ohm resistor is there to limit the current and thus protect the Led and the arduino output .
    The current in the Led will be : I = (5V - V led) / 220
    Vled depends on the led (for a Red led, it is about 1,9V )
    If you replace the resistor with a wire, you'll likely fry the Led and maybe the arduino output too

  2. If one side of the pushbutton is connected to 5V and the other side to the input, yes, the input will be HIGH when the button is pressed, but the arduino inputs are high impedance inputs. Their state is undetermined when the are not connected to anything. Then if the button is released, the input is in an undetermined state .
    That is why you need a pulldown resistor between the input and 0V , so that the input is LOW when the button is not pressed.

alnath:
Hi,

  1. I don't know the arduino project book, but, basically, the 220 Ohm resistor is there to limit the current and thus protect the Led and the arduino output .
    The current in the Led will be : I = (5V - V led) / 220
    Vled depends on the led (for a Red led, it is about 1,9V )
    If you replace the resistor with a wire, you'll likely fry the Led and maybe the arduino output too

I appreciate the quick reply!
I attached a picture of the Arduino in project 02.
I understood what you explained, thank you! but in the picture, the resistors are connecting the LEDs to GND not a power source. Based on what you said, the resistors here are limiting the current that is going to ground. I don't understand why we need resistors here when the current is going to ground anyway.

alnath:
2) If one side of the pushbutton is connected to 5V and the other side to the input, yes, the input will be HIGH when the button is pressed, but the arduino inputs are high impedance inputs. Their state is undetermined when the are not connected to anything. Then if the button is released, the input is in an undetermined state .
That is why you need a pulldown resistor between the input and 0V , so that the input is LOW when the button is not pressed.

well explained! thank you

8100201203_5e816025b7_b.jpg

each Led is connected to an arduino output, which provides 5V when HIGH. Without the resistor, the current through the Led and the output would be too high. The Led and/or the output would fry :wink:

alnath:
each Led is connected to an arduino output, which provides 5V when HIGH. Without the resistor, the current through the Led and the output would be too high. The Led and/or the output would fry :wink:

I think I get it now! Thank you so much :smiley:

Hi Wjdan94, and welcome.

In this case it's not the LED (which can be easily replaced) that you need to protect.
It is the output of your Arduino pin.
An Arduino pin can be loaded with a maximum current of 40 mA.
You should stay away from that 40 mA or more to protect your Arduino, and the easiest way to do that is by a current limiting resistor.
A standard LED does not have any way of current limiting, so it will fail eventually.
But long before that will happen, the Arduino's pin will be dead.

By the way, an Arduino can not output the sum of it's maximum current per pin.
So if you have all pins connected to a LED, and want all of those LEDs to be lit simultaneous then you can't make a design that puts all LEDs on 40 mA.

Keep following those projects from the book.
And keep asking questions like this one if you have them.
You'll find out there's some better or easier ways of doing things.
But the book is composed this way so you will learn some basics too.
That way you will be able to do your own projects in the future.

Thank you to @Crossroads :
"The limit is 200 mA Absolute Maximum per VCC & Gnd pin, then the current limit per port and per pin.

'328P in a DIP package has 1 VCC pin, thus 200mA limit.
'328P in a surface mount package, thus a 400mA limit.
The Notes in Section 29 show the limits per port, totalling 300mA:

ATmega48A/PA/88A/PA/168A/PA/328/P [DATASHEET] 304
8271G–AVR–02/2013
Notes: 1. “Max” means the highest value where the pin is guaranteed to be read as low
2. “Min.” means the lowest value where the pin is guaranteed to be read as high
3. Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady stateconditions (non-transient), the following must be observed:

ATmega48A/PA/88A/PA/168A/PA/328/P:
1] The sum of all IOH, for ports C0 - C5, D0- D4, ADC7, RESET should not exceed 150mA.
2] The sum of all IOH, for ports B0 - B5, D5 - D7, ADC6, XTAL1, XTAL2 should not exceed 150mA.
If IIOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source currgeater than the listed test condition.
4. Although each I/O port can sink more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V)under steady state conditions (non-transient), the following must be observed:

ATmega48A/PA/88A/PA/168A/PA/328/P:
1] The sum of all IOL, for ports C0 - C5, ADC7, ADC6 should not exceed 100mA.
2] The sum of all IOL, for ports B0 - B5, D5 - D7, XTAL1, XTAL2 should not exceed 100mA.
3] The sum of all IOL, for ports D0 - D4, RESET should not exceed 100mA."
If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater
than the listed test condition.hl

MAS3:
Hi Wjdan94, and welcome.

In this case it's not the LED (which can be easily replaced) that you need to protect.
It is the output of your Arduino pin.
An Arduino pin can be loaded with a maximum current of 40 mA.
You should stay away from that 40 mA or more to protect your Arduino, and the easiest way to do that is by a current limiting resistor.
A standard LED does not have any way of current limiting, so it will fail eventually.
But long before that will happen, the Arduino's pin will be dead.

By the way, an Arduino can not output the sum of it's maximum current per pin.
So if you have all pins connected to a LED, and want all of those LEDs to be lit simultaneous then you can't make a design that puts all LEDs on 40 mA.

Keep following those projects from the book.
And keep asking questions like this one if you have them.
You'll find out there's some better or easier ways of doing things.
But the book is composed this way so you will learn some basics too.
That way you will be able to do your own projects in the future.

Thank you so much! This is very helpful.

LarryD:
Thank you to @Crossroads :
"The limit is 200 mA Absolute Maximum per VCC & Gnd pin, then the current limit per port and per pin.

'328P in a DIP package has 1 VCC pin, thus 200mA limit.
'328P in a surface mount package, thus a 400mA limit.
The Notes in Section 29 show the limits per port, totalling 300mA:

ATmega48A/PA/88A/PA/168A/PA/328/P [DATASHEET] 304
8271G–AVR–02/2013
Notes: 1. “Max” means the highest value where the pin is guaranteed to be read as low
2. “Min.” means the lowest value where the pin is guaranteed to be read as high
3. Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady stateconditions (non-transient), the following must be observed:

ATmega48A/PA/88A/PA/168A/PA/328/P:
1] The sum of all IOH, for ports C0 - C5, D0- D4, ADC7, RESET should not exceed 150mA.
2] The sum of all IOH, for ports B0 - B5, D5 - D7, ADC6, XTAL1, XTAL2 should not exceed 150mA.
If IIOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source currgeater than the listed test condition.
4. Although each I/O port can sink more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V)under steady state conditions (non-transient), the following must be observed:

ATmega48A/PA/88A/PA/168A/PA/328/P:
1] The sum of all IOL, for ports C0 - C5, ADC7, ADC6 should not exceed 100mA.
2] The sum of all IOL, for ports B0 - B5, D5 - D7, XTAL1, XTAL2 should not exceed 100mA.
3] The sum of all IOL, for ports D0 - D4, RESET should not exceed 100mA."
If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater
than the listed test condition.hl

Important information. Thank you!

=

Please help with ERROR: stk500_recv() - Couldn't find a solution - IDE 1.x - Arduino Forum

Wjdan94,

Welcome to my world! I asked something about the same project in my thread: Where to place a resistor. - General Electronics - Arduino Forum

Perhaps the sages who replied to me will help you as well. :slight_smile: