Hello guys, I've recently acquired an Arduino UNO R3 and I'm learning electronics with it (trying to remember actually), before jumping to my project.
I have a question that I know is pretty basic but I'm having a hard time understanding, what I want to do is to be sure that I won't fry any I/O port trying to use a lot of stuff in it. As well as the Arduino itself (it's 200mA if I'm not mistaken and 40mA per port right?), so the question is, how can I do this using a transistor? Or I'm going the wrong way here?
I'm sorry if I wasn't clear enough, I meant protecting the Arduino ports so that I wouldn't fry it (either the port or the Arduino) by asking more juice then it can give.
You can however use the transistor like a switch (or a darlington transistor, or even a MOSFET) to turn on a DIFFERENT power source that is capable of sourcing more current.
I know I can't ask for more juice, but let's say I attach a lot of leds in series in the Digital port 3 for instance, and turn them on. If they ask for more then 40mA, won't I be burning that I/O port without some kind of protection? Even if it meant NOT turning them on...
As Wes says, use a transistor to switch an external supply. That way the load on the Arduino i/o pin* is limited to a handful of mA: look here for instance.
You use the word port when you actually mean a pin: a port in Arduino-speak is a collection of pins, as explained here.
If you use a transistor (or darlington transistor, or MOSFET depending on current and/or voltage requirements) then the current flows from the base to the emitter (assuming you're using an NPN transistor. (it would flow from gate to source if using MOSFET).
And that current level is determined by a resistor before the base (not applicable for MOSFETS as they are voltage controlled and have very tiny current pass through). And so your current would never reach a level that could damage your I/O pin unless you put a resistor that was too small.
So if using transistor you will not have an over current condition, so that does solve that problem. However you will need a power source independent from Arduino altogether capable of sourcing needed voltage and current.
So it just depends on your needs.
What are you wanting to power/control with the Arduino?
Thanks for all the help, yes, I did meant I/O Pin.
Actually Wes, I'm still learning so I'm just using it to light some leds for know, fiddling around with resistors, buttons, some ICs, sensors, etc etc....
In the end the project will have at least 32 LEDs, an LCD, and a temperature sensor, for know. I don't believe that all the LEDs would be on at the same time, so no problem with burning some I/O ports, however I wanted to be damn sure of that cos, what if I did wanted to turn all the LEDs and it pulls more then 40mA, or even the 200mA total limit?
I am assuming the LEDs will be in matrix (2D or 3D) of some sorts.
In this case they make specialized ICs to make this job easier. You can also use shift registers and do a bit more of the code yourself. It all depends on if you want a quick easy result or if you want to get very detailed and optimized and learn more (but the second method can take much longer and is more error prone - which helps with the learning process).
Well, not only a Matrix Control but yeah, you got the idea right, I want to learn instead of using something already made, I know it's a longer road, but at least to me is more gratifying. So using the ICs and the library would be a no go for me, at least for now.
With that many LEDs, use a MAX7219 to control them.
You can use a little board like this to break out MAX7219 pins to the individual LEDs.
Then you can have up to 64 LEDs, no worries about burning up pins, and you only need 3 IO pins. http://www.crossroadsfencing.com/BobuinoRev17/
Thanks CrossRoads, but as I've said before, I want to learn, including how to make this from scratch.
The controlling the leds is ok, I can do it with the PCF8574P for instance, however, as I said, the transistor part is kinda black magic and still a question in my head.
I understand the desire to learn, as I have that same feeling a lot, but at the same time there comes a time where you have to know the right tool for the job.
As CrossRoads said for that many LEDs your best bet it to use a MAX7219. It also allows for expanding up to 64 LEDs etc. It will be more cost effective as well then buying a 64 transistors and a bunch of resistors and shift registors etc.
Ok, I promise I'll take a look at it!
However the transistor questions remains, let's say I wanted to create a circuit that would turn 60mA of LEDs in series, I could use a transistor connected to an external voltage suply (let's say a 9V battery) and still the Arduino would be able to control it right?
I would have to connect it something like this right?
I would have to connect it something like this right?
Exactly correct.
Base resistor value may need to change depending on which transistor you use and the current limiting resistors may need to change depending on LED and voltage used (5V, 9V, 12V etc.)
turn 60mA of LEDs in series
That circuit you posted has the LEDs in parallel not series, which is the better way to do it. Since each LED has a forward voltage drop and so to run a bunch of LEDs in series you would need a higher starting voltage.
The one shown on the link (2N3904) will work. You want an NPN transitor not a PNP as you are doing low side switching not high.
The biggest thing to check for is to make sure the current and voltage will be well above what you are using. For example if each LED uses 20mA and you have 4 you will be using 80mA so make sure your transistor can handle currents that high.
In addition make sure the transistor can handle whatever voltage will be across it (9V etc.)
And finally you need to know the gain so you can calculate what value base resistor to use.