← Back to Basic Projects

πŸ”¬ Transistor NPN Switch

Master the most fundamental component in electronics β€” use a BC547 NPN transistor to switch a motor or relay from a weak microcontroller signal.

πŸ“‹ Overview

The transistor is arguably the most important invention of the 20th century. A single BC547 NPN transistor can control 100mA of collector current with just 1mA of base current β€” a current gain (hFE) of 100 or more.

Technical Insight: In saturation mode (switch fully ON), the base-emitter junction is forward-biased at ~0.7V, and the collector-emitter drop is only ~0.2V. By calculating the base resistor: R_B = (V_in βˆ’ 0.7) / I_B, where I_B = I_C / hFE, we ensure the transistor is fully saturated and acting as a closed switch β€” not a linear amplifier.

In simple terms: The transistor is a water tap β€” a tiny signal at the base 'handle' controls a large flow from collector to emitter. Arduino is too weak to power a motor directly, but with a transistor between them, the Arduino controls the motor with no risk.

What you'll learn: BJT operation modes (cutoff, saturation, active), base resistor calculation, flyback diode need for inductive loads, and why transistors replaced mechanical relays.

Estimated time: 30-40 minutes. Difficulty: ⭐⭐ Easy β€” essential electronics theory brought to life.

🧩 Components Needed

ComponentSpecificationQtyNotes
Arduino Uno R35V1
BC547 NPN TransistorhFE β‰₯ 100, 45V, 100mA1Or 2N2222 equivalent
Small DC Motor / LED5V, <100mA1The controlled load
Resistor (base)1kΞ©1Controls base current
1N4007 DiodeFlyback protection1Needed for motor loads
Breadboard + WiresHalf-size1

πŸ—ΊοΈ Component Pin Mapping

Transistor NPN Switch Component Pin Mapping Infographic

πŸ“– Step-by-Step Tutorial

1

Identify Transistor Pins

Hold BC547 with flat face toward you, legs pointing down. Left = Collector, Middle = Base, Right = Emitter.
2

Wire the Circuit

Emitter β†’ GND. Base β†’ 1kΞ© resistor β†’ Arduino pin 9. Motor+ β†’ 5V (or battery). Motorβˆ’ β†’ Collector. Add flyback diode across motor (cathode to +).
3

Upload Blink Code

Upload the code. The motor will turn ON for 1 second, then OFF for 1 second. The transistor switches it from Arduino's PWM pin.
4

Measure Base Current

Use a multimeter between pin 9 and base resistor. You should read ~4mA. Between battery+ and motor, you'll see ~50–80mA β€” the transistor amplifies it!
5

PWM Speed Control

Change digitalWrite to analogWrite and vary speed from 0–255.
πŸ’‘
Always use a flyback (freewheeling) diode in parallel with any motor or relay coil β€” connected in reverse (cathode to positive). When the transistor turns OFF, the coil collapses and creates a voltage spike that can destroy the transistor without this diode protection.

πŸ’» Arduino Code

transistor_switch.ino
INO
// Transistor NPN Switch β€” Volt X
// BC547 switching a DC motor via Arduino PWM

const int CTRL_PIN = 9; // Connected to base via 1kΞ© resistor

void setup() {
  pinMode(CTRL_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // === Full ON (digital) ===
  Serial.println("Motor ON  (full speed)");
  digitalWrite(CTRL_PIN, HIGH);
  delay(2000);

  // === Full OFF ===
  Serial.println("Motor OFF");
  digitalWrite(CTRL_PIN, LOW);
  delay(1000);

  // === Half Speed via PWM ===
  Serial.println("Motor HALF speed (PWM 128)");
  analogWrite(CTRL_PIN, 128);
  delay(2000);

⭐Reviews & Ratings

β€”0 reviews
5β˜…
0
4β˜…
0
3β˜…
0
2β˜…
0
1β˜…
0
...

Loading reviews...

volt-X / Transistor NPN Switch β€” Arduino Tutorial