(Note. I programmed the microcontroller to put pin digital 9 to HIGH.)
I'm confused as to where I need to place the resistor in circuits and other components. Also why does 1. work but not 3. seeing that the only difference is that the positive charge is coming from the digital pin 9?
You are right there must have been some connection issue somewhere. Interesting. But just in general... should the resistor go before or after the LED, in the above circuits? i.e. which is best practice and why.
It doesn't matter....I'd go 51% with the resistor closer to the Arduino pin. Just for safety's sake, if you mistakenly short something out the resistor has a better chance of protecting the pin from overcurrent. Suppose you mistakenly short out the LED anode to GND. In configuration (4) that you drew you'd be shorting out the Arduino pin and quite possibly damaging the microcontroller. In configuration (3) the pin is protected by the resistor. Of course, you could always short the "wrong" end of the resistor to ground too, so it's no guarantee of anything.....
--
The Quick Shield: breakout all 28 pins to quick-connect terminals
But just in general... should the resistor go before or after the LED, in the above circuits? i.e. which is best practice and why
My take on this is 1 or 3 - here's why:
It is common "sense" to envision current as flowing from high potential (voltage) to ground (ie, from positive to negative). In reality, this isn't true at all (and nothing really "flows" anyhow), but the visualization is easy to see.
Resistors are used to decrease current in a circuit (thus lowering the current through the LED in this case), so from the "flow" perspective above, it makes more sense that the current flows out the pin, goes thru the resistor (and lowering current), then thru the LED, then to ground.
Once again, in reality this isn't how it actually works, and it ultimately doesn't matter which side the resistor is on, as RuggedCircuits has already noted...
One of the analogies for electrical systems is plumbing, where we have pipe (wire), water(current), reservoirs, tanks or rivers (batteries or capacitors) and taps or faucets (resistors).
To control flow of water you always have the tap in the line before the appliance. Hence resistor goes before LED.
but again it does not really matter, to use plumbing if you have a restrictive area (ie resistor) anywhere in the line the end result will be less flow
(besides water is a horrible analogy to electricity)