Bu projeyi gerçekten kurmak istersen parçaları hobidevre.com'dan temin edebilirsin →
Get the parts
If you want to build a real circuit, you can get the parts from hobidevre.com → hobidevre.com →
More build guides: hobidevre.com/blog
Why use a transistor
A microcontroller pin is good at sending a logic level but poor at supplying power. A single LED with a resistor is fine. A strip of LEDs, a motor or a relay coil can need tens or hundreds of milliamps, far more than a pin should provide.
A transistor solves this by using the small pin current to control a separate path from the supply through the load. The heavy current never flows through the chip, and the pin only has to charge or discharge the transistor base.
NPN low-side switching
In the common low-side arrangement, the emitter connects to ground and the load connects between the positive supply and the collector. The pin drives the base through a resistor. When the pin goes high, current flows into the base and the transistor conducts from collector to emitter, completing the load circuit.
The control supply and the load supply must share a ground. If they do not, the base voltage has no reference and the transistor may never turn on reliably. This is the most common wiring mistake when a load uses its own adapter.
Choosing the base resistor
The base resistor sets the base current. A useful design rule is to assume the transistor will amplify by about ten rather than trusting the much larger figure in the datasheet. To switch a one hundred milliamp load, plan for roughly ten milliamps of base current.
With a five volt pin and about 0.7 volts across the base-emitter junction, the resistor must drop roughly 4.3 volts at ten milliamps, which gives about 430 ohm. A 470 ohm standard part is a sensible choice. The resistor protects both the pin and the base, so it is never optional.
Saturation and voltage drop
When used as a switch, the transistor should be driven into saturation, where a further increase in base current barely changes the collector current. In saturation the voltage across collector and emitter is small, often around two tenths of a volt, so little power is wasted in the transistor.
A transistor that is only partly on sits in its linear region, drops more voltage and heats up. That is what happens when the base resistor is too large or the load is larger than planned. Check the temperature after a few minutes of operation.
Inductive loads
A relay coil or motor produces a voltage spike when current is switched off. Without a path for that energy, the spike can damage the transistor or the pin driving it. A diode placed across the coil, with its cathode toward the positive supply, gives the current a safe route during turn-off.
Driver modules already include this protection. If you build the stage yourself, add the diode every time the load is inductive. For a relay that switches a separate higher-power circuit, keep the low-voltage control side physically separate from the load wiring.
Common mistakes
- Omitting the base resistor and relying on the pin’s current limit.
- Forgetting the shared ground between control and load supplies.
- Expecting a transistor to block current in the wrong direction, which calls for a different arrangement.
- Exceeding the collector current or power rating “just for a test".
Another frequent issue is assuming the transistor is on when the software never sets the pin as an output. Confirm the pin mode in code before blaming the wiring.
Worked example and checklist
- Decide the load current from the part’s rating, not from a guess.
- Choose an NPN transistor rated above that current and the supply voltage.
- Set the base current to about one tenth of the load current.
- Calculate the base resistor from the pin voltage minus 0.7 volts.
- Connect the emitter to ground and the load to the collector.
- Add a flyback diode for any coil, then test with a meter.
Measure the voltage across the load when the pin is high. It should be close to the supply; a much lower reading means the transistor is not in saturation.
Frequently asked questions
Why not drive the load directly from the pin?
A pin is specified for a small current. A transistor carries the load current from a separate supply while the pin provides only the base current.
What happens if the base resistor is too small?
Base current rises and can exceed what the pin or the base can accept. Choose the resistor from the required base current rather than picking the smallest part available.
Do I still need a resistor for an LED in the load?
Yes. The transistor switches the branch; it does not replace the resistor that limits current through the LED.
Can I switch a higher voltage load?
Only with a suitably rated device and correct isolation. For mains loads, use a professionally made, rated module and qualified advice.