So first off, digital pins in the arduino when set on output will output 5 volts correct? arduino.cc says each i/o will give off 40 mA dc current (correct me if im wrong cause im entirely inexperienced with electronics).
So if i add for example a 1k resistor into the mix then what is the current now. Im not sure cause i know the formula V = I *R, but arent the current and voltage independent-fixed-values? or is the voltage 5v and is there an internal resistance in the arduino of .. 125 ohms cause 5/125 = 0.040A. thus would i just add on the 1k to that resistance (since its obviously in series) to make it 1125 and my result is 5/ 1125 = 0.004A.
What im trying to do is just set up a 2n2222A transistor (not rocket science, i know) but i read that i should aim for 0.6-0.7 volts into its base. So i could do it by trial and error and a volt meter, but id just like to know how to do the calculation to know what resistance would be appropriate.
The arduino will pretty much act as a 5v source up to the 40ma limit. A 1K resistor will allow 5ma etc.
I'll be honest though, I'm not real sure how that helps with your transistor question. Maybe ask again or google "transistor arduino" or variants of that.
It does not say that each pin will output (source) 40mA, it say that 40mA is the maximal allowed output current. So for proper design you should always have at least 125ohm load resistance.
Otherwise, if you are lucky the internal resistance limits the current enought to prevent the chip to overheat, if you are unlucky there are new chips to buy.
For the transistor, usually you should design the resistor to give a fixed base current, the base emitter voltage (npn) is more or less fixed by the diode type junction at 0.7V.
So the resistor should be design to give the intended base current with a voltage drop of 5V-0.7V=4.3V
just here to say never exceed 40 mA
Better stay below. It's a maximum rating!
In other words if you load an output pin with less then 125 ohms toward ground your Atmel will be blasted.
Do you want the transistor to be a driver for higher loads than 40 mA?
Edit. M Lundin was faster by nanoseconds, totally agree with him
The Arduino output pin does not determine how much current is drawn from it, only the load resistance determines that. The 40ma max pin current is a maximum rating to prevent damage from the output pin driver.
As far as setting up your transistor driver, first you have to know how much total collector current you want to pass and then find out the current amplification factor, beta, of the transistor. You will then know the minimum base current that will be needed. Base resistor value will be (Vpin - .7) divided by desired base current.
A bipolar transistor is not a voltage controlled device. The question is for what current into the base you should be aiming. If you are using the transistor as a switch you want to saturate it. That is you want to achieve the following:
Have as much current into the base as possible in order to decrease the resistance of the transistor as much as possible and to ensure that it switches as fast as possible.
Do not overload the output pin --> keep current below 40 mA
Do not overload the transistor --> keep below the maximum allowed base current
So compute the smallest resistor that still allows you to stick to (2) and (3) and add some safety margin.