Silly basic question but I can't think of the answer.
I know how to turn an LED on and off by coding digitalWrite(ledPin, HIGH); or digitalWrite(ledPin, LOW); when attached to say pin 10.
How do I turn the LEDs on and off if they have a different power source?
I will need to power them with some batteries. So how do I wire that and code that?
Code stays the same but the circuit you build is much different. You'll have to use a transistor with each LED you want to control. The 5V coming from the arduino trips the transistor to allow the higher voltage to flow to the LEDs. Now what transistor will work best for you depends on the power requirements of the LEDs.
it should be noted that you need a current limiting resistor (~1k) tween the arduino and the base of the transistor, as it shorts to ground also
Thanks.
What type of transistor would I need ?
Something like this NPN 2N3904 from Sparkfun?
well
-
if you look at the datasheet you can see how much current can pass tru a 3904, its about 200ma, is that enough for what your your doing? you need to know
-
sparkfun, that's your call, me I would buy 100 of them for 12 bucks at any electronic supply site
Look at this:-
http://www.thebox.myzen.co.uk/Workshop/Motors_1.html
It's about motors but applies to any load.
For using external power supplies see:-
http://www.thebox.myzen.co.uk/Tutorial/Power_Supplies.html
Thanks Grumpy Mike. That diagram is very helpful.