Transistor as a switch

Wendy

Joined Mar 24, 2008
23,839
As a general (very general, lots of exceptions) rule of thumb the emitter is grounded, so the base to emitter current (which turns the transistor on/off) doesn't get involved. The collector/emitter turns on/off, but you have to be carefull it doesn't enter its linear region.
 

Thread Starter

sportsfan27

Joined Jan 29, 2009
43
What I'd like to happen is have a microcontroller turn on the transistors every couple of seconds. The transistors will act as a switch for several LEDs.
 

mik3

Joined Feb 4, 2008
4,843
What I'd like to happen is have a microcontroller turn on the transistors every couple of seconds. The transistors will act as a switch for several LEDs.
Use NPN transistors, with their emitter at ground, a resistor (about 1K) between the base and the microcontroller and your load between the collector and Vcc.
 

Thread Starter

sportsfan27

Joined Jan 29, 2009
43
That's exactly the circuit I have. I don't think I was clear enough, though; my question should have been, how do I program the microcontroller to turn the transistor on and off?
 

SgtWookie

Joined Jul 17, 2007
22,230
Set the pins you're using to output.

Set the pin to a logic high (1) to turn the transistor on.
Waste some time in a delay loop.
Set the pin to a logic low (0) to turn the transistor off.
Waste some time in a delay loop.
Repeat
 

mik3

Joined Feb 4, 2008
4,843
I quite disagree with Sgt to waist time in a loop. You can set the particular output to 1, make some other calculations with the uC and then set the output to 0 if desired.
 

hgmjr

Joined Jan 28, 2005
9,027
Perhaps you would be interested in reading up on the use of a transistor as a switch. The link I have provided takes you to the section on transistors operated as switches. It will provide with some background info so that you will better appreciate the other comments your post has garnered.

hgmjr
 

thatoneguy

Joined Feb 19, 2009
6,359
I quite disagree with Sgt to waist time in a loop. You can set the particular output to 1, make some other calculations with the uC and then set the output to 0 if desired.
While very true, what should the uC be calculating if it's entire function in life is to blink LEDs on and off?

Getting philosophical, I suppose the uC may be more eager to blink the LED if he also gets to calculate 1000 digits of pi, followed by 1000 digits of e, but in the end, it is all wasting cycles, since the results can't be displayed. Unless the silicological portion of the "id" is somehow boosted, causing the now happy and confident uC to use less power.
 

SgtWookie

Joined Jul 17, 2007
22,230
Mik3,
My suggestion was IAW the "KISS" principle. ;)

Sure, I could've suggested that our OP utilize an interrupt when timer0 or timer1 overflowed and increment a counter, disabling and re-enabling the interrupt during the service routine, but for this simple exercise such would be rather bewildering for a "n00b".

As it is, just coding delay loops in assembler can be intimidating.
 
Top