Led and resistors?

Hello!

I am completely new to small electronics, but have recently acquired an arduino nano. I am trying to create a simple traffic light and I have already created the code i am going to use.

The circuit is going to be powered by a 9V battery. I will solder in an on/off button.

A potentiometer will control the time of the loop and a push button will start the loop. When the button is pressed, a couple of leds will light up for n seconds.

My question is, how many simple leds can i connect and light up at the same time? Can i connect two or three leds to the same pin? Can i light up several pins at the same time? The leds i will use are 5V and can handle a maximum of 20mA. Do i need resistors?

Thanks for your answers!

Yes you need resistors. The value of the resistor determines the current you run the LED at. Use Ohm's law* to determine resistance needed. Put your LEDs in series with the resistor. Hook the anode end to the pin, and the cathode to the ground, with the resistor on either side (it doesn't matter which.) Make the pin HIGH to turn the LED on, and LOW to turn it off.

Each pin can handle 40 mA give or take, but you have a maximum of 200 mA for the whole board, assuming you've got an Arduino Uno.

  • Ohms law: (V=IR)
Vcc - LED running voltage drop (volts)
--------------------------------------- = resistor to use (ohms)
diode running current (mA/1000 = amps)

Most red, yellow and green LEDs drop the voltage about 2 volts when they turn on. If you run the LEDs at 10 milliamps (use a high brightness LED - it will be bright at 10mA) on a 5 volt supply, then calculate the resistance like this:

5 volts - 2 volts      3volts
-------- --------- = ----------  =  [b]300 ohms[/b]
   10 milliamps       0.01 amps

You'll be hard pressed to find a 300 ohm resistor, but 330 ohm resistors are everywhere. It'll run at ~8 mA.

Thanks for your answer!

Does this mean i can connect 4 red leds, each with a 330ohm resistor to one pin to control them all and make the traffic light even brighter?

The board I have is an Arduino Nano. Will that change what resistors i Need?

ivarholti:
Thanks for your answer!

Does this mean i can connect 4 red leds, each with a 330ohm resistor to one pin to control them all and make the traffic light even brighter?

The board I have is an Arduino Nano. Will that change what resistors i Need?

I believe it's the same. I don't have a nano, so check the spec sheets. You can find them through the 'products' link in the menus. Don't push the current to the limit for extended periods. So limit it to 2 or at most 3 LEDs per pin for the best longevity. Be sure to put a resistor on every LED. Aim to keep the draw on any pin 20 milliamps or less, and you will never experience overload related failure.

ps, for your application, I would guess the limiting factor would be the 200 mA maximum for the board though. If you are using a lot of LEDs, remember to limit them to only a few mA each, to keep the total (of everything that is exterior to the Arduino board) under 200 mA.

ChrisTenone:
ps, for your application, I would guess the limiting factor would be the 200 mA maximum for the board though. If you are using a lot of LEDs, remember to limit them to only a few mA each, to keep the total (of everything that is exterior to the Arduino board) under 200 mA.

If I understood the tech specs correctly then yes they are the same.

I am now thinking about running 2 leds per pin and a total of 6 pins at the same time. That would mean, with a 330 ohm resistor on every led, that a maximum of 18 mA per pin and 108 mA for the whole board is drawn right?

If i have a simple push button and a potentiometer, do I need to account for any current drawn? They will only be used as inputs. And what resistors do i need here? I have read somewhere that i should have a 10k ohm resistor for the potentiometer. Is that right?

I haven't checked your arithmetic - your logic makes sense. 10K pots work well as inputs. Use pots, and switches and other resistive inputs with the internal pull-up resistors.

It sounds like your project is ready to put together and test in the real world. See how it works.

ChrisTenone:
I haven't checked your arithmetic - your logic makes sense. 10K pots work well as inputs. Use pots, and switches and other resistive inputs with the internal pull-up resistors.

It sounds like your project is ready to put together and test in the real world. See how it works.

Does a 10K pot need a 10K resistor or is that implemented already in the potentiometer? And how does the internal pull-up resistors work? Are there built in resistors already in the board?

Sorry if my questions are stupid, and thanks for your help. :slight_smile:

And how does the internal pull-up resistors work?

Not sure what you mean here. It is a pull up resistor of about 40K between the input pin and 5V. To enable it you uses the call
pinMode(pin, INPUT_PULLUP )

Are there built in resistors already in the board?

No.

Does a 10K pot need a 10K resistor

No. But how are you thinking of using it?

Grumpy_Mike:
Not sure what you mean here. It is a pull up resistor of about 40K between the input pin and 5V. To enable it you uses the call
pinMode(pin, INPUT_PULLUP )
No.
No. But how are you thinking of using it?

Aah okay.

I am thinking of using it as only a signal that defines a variable which in turn controls a delay time. Can I do this by just connecting the potentiometer straight to one of the analog input pins without any resistor in between?

And does a simple push button need a resistor too?

Can I do this by just connecting the potentiometer straight to one of the analog input pins without any resistor in between?

Yes. One end to +5V the other to ground and the slider to the analogue input.

And does a simple push button need a resistor too?

Not if you connect it correctly, which is the switch between input and ground and enable the internal pull up resistors in the code. See the reference for the pinMode call.

Okay, thank you both very much for all the help. I think I have everything figured out now, and will go get the components I need tomorrow.

Thanks! :slight_smile:

With 9V power supply you can make it more efficient to power the LEDs directly from the battery with help of a transistor. This way you can connect a few LEDs in series both saving current from battery and reducing current through Arduino - you can get more brightness without being afraid you load Arduino power source too much.