Same-day dispatch before 2 PM · Free delivery over ₹999 · GST invoices Get the appPrices incl. GST
Geekobot
Snap & SendNEWGeeko AIWhere's myOrder
Log in
Products
  • Projects
    • Component guidesHow parts work, with code you can run
    • Learning pathsFrom your first LED to your first robot
    • Workshops & eventsOnline sessions for makers and classes
    • ElectrolarkFree guided builds, simulator and certificates
    • Students & teachersStudent discount and classroom help
    • CommunityShare builds and ask other makers
    • CalculatorsOhm's law, LED resistor, 555 and 100+ more
    • Circuit builderWire parts and run the circuit, powered by Electrolark
    • Geeko AIAsk what to buy or how to wire it
    • Snap & SendPhotograph a part or list, we find it
    • Part finderAnswer a few questions, get the right part
    • Compatibility checkWill these two parts work together?
    • Compare partsSpecs side by side
    • Business & bulk ordersGST invoices, credit and volume prices
    • Request a quotationSend your list, get a quote
    • Classroom kitsPer-student kits and lab bundles
    • Gift cardsFor students, teams and events
  • Atal Tinkering Lab
BOM to cart
Geekobot

Components, kits and know-how for makers, students, engineers, labs and businesses across India.

Ask Geeko AIOrders, parts and projects, any timeEmail supportReply within 1 working dayGet the Geekobot appAdd it to your home screen, free

Follow us

Shop

  • Boards & SBCs
  • Sensors & Modules
  • IoT & Wireless
  • Drone & FPV
  • 3D Printing
  • Filaments & Resins
  • Motors & Drivers
  • Power & Batteries
  • Semiconductors
  • Passive
  • Displays & LEDs
  • Switches & Relays
  • Wires & Cables
  • Prototyping
  • Tools & Test
  • Robotics
  • STEM Kits
  • Atal Tinkering Lab
  • Mechanical Parts
  • Audio

Orders

  • Track your order
  • Help & support
  • Shipping and delivery
  • Refunds and cancellation
  • Contact us

Learn

  • Projects
  • Geeko AI project assistant
  • Learning paths
  • Guides
  • Calculators
  • Electrolark: free guided builds

Part tools

  • Part finder
  • Compare parts
  • Will it work with my board?

Institutions

  • Classroom kits
  • Atal Tinkering Lab
  • Students & teachers
  • Workshops & Events

Business

  • Business & education
  • Request a quotation
  • BOM bulk upload
  • Quick order by SKU

Company

  • About Geekobot
  • Community
  • Gift cards
  • Terms & conditions
  • Privacy policy
  • Product directory
  • Sitemap

© 2026 Geekobot, a trade name of OLatus Systems Private Limited. All rights reserved.

20, 1st Floor, Neeladri Complex, 10th Cross, Sampige Rd, 2nd Main, Malleshwaram, Bengaluru, Karnataka 560003 · GSTIN 29AACCO0462F1ZM

+91 91810 15607 · connect@geekobot.in · Monday to Saturday, 10 AM to 2 PM IST

UPI · CARDS · NETBANKING · GST INVOICES

ShopProjectsGeeko AIGuides
Compare 0 parts →
Log in

Shop by category

Shop all components
  • Boards & SBCs1,910 products
    • Alternative Single Board Computers
    • Arduino Ecosystem
    • FPGA & Logic Boards
    • Microcontroller & Wireless Boards
    View all
  • Sensors & Modules4,701 products
    • Biomedical & Heart Rate
    • Current, Voltage & Power
    • Force, Weight & Pressure
    • Gas, Weather & Environmental
    View all
  • IoT & Wireless2,314 products
    • RF Modules
    • RFID & NFC
    • Antennas & RF Accessories
    • Cameras & Smart Vision
    View all
  • Drone & FPV3,558 products
    • Flight Control & Navigation
    • FPV Video & Optics
    • Frames & Structural Parts
    • Motors & Propulsion
    View all
  • 3D Printing2,204 products
    • 3D Printers
    • 3D Scanners & Digitizers
    • Laser Engravers & Cutters
    • Material Management & Upgrades
    View all
  • Filaments & Resins1,472 products
    • Filaments
    • Photopolymer Resins
    View all
  • Motors & Drivers463 products
    • BLDC Motor Drivers
    • DC & Geared Motors
    • DC Motor Drivers
    • Linear Actuators & Solenoids
    View all
  • Power & Batteries557 products
    • Battery Holders & Connectors
    • Breadboard Power
    • Chargers & BMS
    • DC-DC Converters
    View all
  • Semiconductors295 products
    • Diodes & Rectifiers
    • Interface & RF Encoder ICs
    • Logic ICs (74xx)
    • Logic ICs (CD4000)
    View all
  • Passive67 products
    • Capacitors
    • Circuit Protection
    • Crystals & Oscillators
    • Inductors
    View all
  • Displays & LEDs572 products
    • 7-Segment & Dot Matrix
    • Addressable LEDs
    • Character LCDs
    • Graphic LCDs
    View all
  • Switches & Relays184 products
    • Keypads & Touch
    • Push Buttons & Tactile
    • Relay Modules
    • Relays
    View all
  • Wires & Cables233 products
    • Board-to-Wire Connectors
    • Crimp & Splice
    • Headers & Dupont
    • Heat Shrink & Sleeving
    View all
  • Prototyping101 products
    • Breadboards
    • Interface Modules
    • PCBs & Perfboards
    View all
  • Tools & Test717 products
    • Bench Power Supplies
    • Hand Tools
    • Measuring Tools
    • Meters & Testers
    View all
  • Robotics180 products
    • Humanoid & Legged Robots
    • Robot Chassis & Platforms
    • Robotic Arms & Grippers
    • Wheels & Casters
    View all
  • STEM Kits268 products
    • Arduino Learning Kits
    • Coding & IoT Kits
    • Early Coding (Ages 3-8)
    • Invention Kits
    View all
  • Atal Tinkering Lab196 products
    • Package 1: Electronics, Robotics, IoT and Sensors
    • Package 2: Rapid Prototyping Tools
    • Package 3: Mechanical, Electrical and Measurement Tools
    • Package 4: Power Supply, Accessories and Safety Equipment
    View all
  • Mechanical Parts212 products
    • Bearings
    • Brackets & Mounts
    • Couplers
    • Fasteners & Standoffs
    View all
  • Audio109 products
    • Amplifier Modules
    • Buzzers & Sirens
    • Speakers
    View all
  1. Home
  2. ›Guides
  3. ›Semiconductors & ICs
  4. ›Transistors and MOSFETs as Switches
Step 14 of 18 in Electronics from zeroPart of a learning path.
Next

How-to · Intermediate · 4 min read

Transistors and MOSFETs as Switches

BC547, 2N2222, IRLZ44N

By Geekobot Learning Team · Updated 24 Oct 2026

I'm using
Wiring, code and the Run it panels follow your board.
On this page
Short answerWhy you need a transistorSwitching with an NPN transistor (and calculating the base resistor)Switching with a MOSFETAlways add a flyback diode for coils and motorsPWM a 12 V LED strip or motor with a MOSFETTry itCommon mistakesFAQsParts and next steps
Short answer

A transistor lets a small microcontroller signal switch a much larger current. For loads up to a few hundred milliamps, an NPN transistor such as the 2N2222 or BC547 with a base resistor works well. For amps, use a logic-level N-channel MOSFET such as the IRLZ44N, which turns fully on from a 5 V pin. Add a flyback diode across motors and relay coils.

Key specs at a glance

BC547 (NPN)
45 V, 100 mA
2N2222 / PN2222 (NPN)
40 V, 600 mA
TIP120 (Darlington)
60 V, 5 A, about 1 to 2 V drop
IRLZ44N (logic-level MOSFET)
55 V, Rds(on) about 0.025 Ω at 5 V gate
IRF540N
100 V, needs about 10 V on the gate to turn fully on
Flyback diode
1N4007 (slow loads), 1N5819 or 1N4148 (fast PWM)
01

Why you need a transistor

A microcontroller pin supplies about 8 to 20 mA at 3.3 or 5 V. A motor, a relay coil, a solenoid or an LED strip needs tens of milliamps to several amps, often at 12 V. A transistor placed on the low side (between the load and ground) acts as a switch: the pin controls it, and the separate supply powers the load.

02

Switching with an NPN transistor (and calculating the base resistor)

Wire the load from +V to the collector, the emitter to ground, and the base to the microcontroller pin through a resistor. To make sure the transistor is fully on (saturated), use a forced gain of about 10:

Base current

Ib = load current / 10

Base resistor

Rb = (pin voltage - 0.7 V) / Ib

Example

a relay coil drawing 80 mA from a 5 V Arduino pin: Ib = 8 mA, Rb = (5 - 0.7) / 0.008 = 537 Ω, so use 470 or 560 Ω. From a 3.3 V ESP32 pin: (3.3 - 0.7) / 0.008 = 325 Ω, so use 330 Ω.

03

Switching with a MOSFET

A MOSFET is controlled by gate voltage, not current, so it draws almost nothing from the pin once switched. Wire the load from +V to the drain, the source to ground, the gate to the pin through a 100 to 220 Ω resistor, and a 10 kΩ resistor from gate to ground so the load stays off while the microcontroller boots.

The key spec is Rds(on) at your gate voltage. A "logic-level" MOSFET specifies low Rds(on) at 4.5 V or less. The IRLZ44N is excellent from 5 V. From 3.3 V boards, choose parts specified at 2.5 V such as the AO3400 (SOT-23), or drive the gate of a larger MOSFET with a small transistor or gate driver.

PartTypeGood from 5 V pin?Good from 3.3 V pin?Use
BC547NPN BJTYes (to 100 mA)Yes (to 100 mA)LEDs, small buzzers
2N2222NPN BJTYes (to about 500 mA)YesRelays, small motors
IRLZ44NLogic-level MOSFETYes, to many ampsPartly; limit to about 1 to 2 ALED strips, 12 V motors, solenoids
IRF540N / IRFZ44NStandard MOSFETNo, needs 10 V gateNoUse with a gate driver
AO3400Logic-level MOSFET (SMD)YesYes, to about 2 ACompact 3.3 V designs
ULN20037-channel Darlington arrayYes, 500 mA per channelYesRelays, unipolar steppers
BC547
Type:
NPN BJT
Good from 5 V pin?:
Yes (to 100 mA)
Good from 3.3 V pin?:
Yes (to 100 mA)
Use:
LEDs, small buzzers
2N2222
Type:
NPN BJT
Good from 5 V pin?:
Yes (to about 500 mA)
Good from 3.3 V pin?:
Yes
Use:
Relays, small motors
IRLZ44N
Type:
Logic-level MOSFET
Good from 5 V pin?:
Yes, to many amps
Good from 3.3 V pin?:
Partly; limit to about 1 to 2 A
Use:
LED strips, 12 V motors, solenoids
IRF540N / IRFZ44N
Type:
Standard MOSFET
Good from 5 V pin?:
No, needs 10 V gate
Good from 3.3 V pin?:
No
Use:
Use with a gate driver
AO3400
Type:
Logic-level MOSFET (SMD)
Good from 5 V pin?:
Yes
Good from 3.3 V pin?:
Yes, to about 2 A
Use:
Compact 3.3 V designs
ULN2003
Type:
7-channel Darlington array
Good from 5 V pin?:
Yes, 500 mA per channel
Good from 3.3 V pin?:
Yes
Use:
Relays, unipolar steppers
04

Always add a flyback diode for coils and motors

When current through a coil (relay, solenoid, motor) is switched off, the coil generates a voltage spike that can destroy the transistor. Place a diode across the load, cathode (striped end) to +V, anode to the transistor side. Use a 1N4007 for relays and solenoids, and a Schottky such as the 1N5819 for PWM-driven motors. Relay modules and ULN2003 chips include these diodes.

05

PWM a 12 V LED strip or motor with a MOSFET

MOSFET PWM dimmer · Arduino C++Verify & upload in Electrolark
const int GATE = 9;          // PWM pin to MOSFET gate via 220 ohm

void setup() { pinMode(GATE, OUTPUT); }

void loop() {
  for (int d = 0; d <= 255; d += 5) { analogWrite(GATE, d); delay(30); }
  for (int d = 255; d >= 0; d -= 5) { analogWrite(GATE, d); delay(30); }
}
06

Try it: Transistor base resistor calculator

Change the values and the diagram and results update as you type.

07

Common mistakes to avoid

  • !Leaving out the base or gate resistor.
  • !Using an IRF540N or IRFZ44N straight from a 5 V or 3.3 V pin; it only half turns on and overheats.
  • !Forgetting the flyback diode on relays, solenoids and motors.
  • !Not connecting the load supply's ground to the microcontroller ground.
  • !Putting an NPN or N-channel switch on the high side, where it cannot turn fully on.
08

Frequently asked questions

Should I use a transistor or a MOSFET?

Use an NPN transistor for loads up to a few hundred milliamps. Use a logic-level MOSFET for higher currents and PWM, since it wastes far less power as heat.

What is a logic-level MOSFET?

A MOSFET whose datasheet specifies low on-resistance at a gate voltage of 4.5 V or less, so a microcontroller pin can switch it fully on. Look for Rds(on) quoted at Vgs = 4.5 V or 2.5 V.

Can an ESP32 drive an IRLZ44N?

It will switch on, but at 3.3 V the resistance is higher than at 5 V, so keep currents modest, or use a MOSFET specified at 2.5 V, or a small gate-driver stage.

What base resistor should I use for a 2N2222?

Rb = (pin voltage - 0.7) / (load current / 10). For 100 mA from a 5 V pin, about 430 Ω; 1 kΩ is a common safe value for loads under 40 mA.

Why does my transistor get hot?

It is not fully saturated (base resistor too large, or gate voltage too low for the MOSFET), or the load exceeds its rating. Recalculate the base resistor or choose a logic-level MOSFET.

Parts for this guide

  • ULN2003 Stepper Motor Driver Board
    ₹36View
  • Resistor Assortment Kit (30 Values)
    ₹33View
Shop TransistorsShop MOSFETsShop Diodes & Rectifiers

Calculators

Transistor base resistor calculator

Terms in this guide

BJTBipolar junction transistor (NPN or PNP), controlled by a small base current. Examples: BC547, 2N2222.MOSFETMetal-oxide-semiconductor field-effect transistor, controlled by gate voltage. Efficient for switching large currents.Logic-level MOSFETA MOSFET that turns fully on with a gate voltage of 4.5 V or less, so a microcontroller can drive it.Flyback diodeA diode placed across a coil (relay, motor, solenoid) to absorb the voltage spike when current is switched off.RDS(on)A MOSFET's resistance when fully on; lower means less heat.Low-side switchA switch placed between the load and ground; the easiest way to switch loads with NPN transistors and N-channel MOSFETs.PWMPulse-width modulation: switching a signal on and off quickly so its average sets brightness, speed or position.

Projects that use it

Put this into practice: 8 step-by-step builds in our project library use parts from this guide.

Beginner · 1 hourDC fan speed controllerView projectBeginner · 1 hourTemperature-controlled laptop stand fanView projectIntermediate · 1–2 hours555 PWM motor speed controllerView project
Browse all 8 projects

Keep learning

Component guideBeginnerRelay ModulesA relay module is an electrically controlled switch that lets a microcontroller turn a separate circuit on or off, such as a 12 V pump or a mains lamp.4 min read · Switches, Relays & InputComponent guideBeginnerDC Motors ExplainedA brushed DC motor spins when current flows through it: voltage sets the speed and the load sets the current it draws.4 min read · Motors & MotionComponent guideBeginnerLEDs ExplainedAn LED (light-emitting diode) lights when current flows from its longer leg (anode, +) to its shorter leg (cathode, -).3 min read · Displays & LEDsComponent guideBeginnerResistors ExplainedWhat resistors do, how to read 4- and 5-band colour codes and SMD codes, Ohm's law, power ratings, standard values and uses: LEDs, pull-ups, dividers.4 min read · Passive Components

Sources

  • P2N2222A datasheet (onsemi)
  • BC547 datasheet (onsemi)
  • IRLZ44N datasheet (Infineon)
  • IRF540N datasheet (Infineon)
  • AO3400A datasheet (Alpha & Omega Semiconductor)
  • ULN2003A datasheet (Texas Instruments)

Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.

On this page
Short answerWhy you need a transistorSwitching with an NPN transistor (and calculating the base resistor)Switching with a MOSFETAlways add a flyback diode for coils and motorsPWM a 12 V LED strip or motor with a MOSFETTry itCommon mistakesFAQsParts and next steps
Need a hand?Ask Geeko AI which part fits your project, or talk to the Geekobot team.Ask Geeko AIHelp & support

Parts for this guide2 items · ₹69

ULN2003 Stepper Motor Driver Board · Resistor Assortment Kit (30 Values)

Run itChange the inputs and watch the output
Load (LED strip) OFF
0 %Gate duty

A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.

Ask the Community

Ask a question